Questions tagged [html]

HTML (HyperText Markup Language) is the markup language for creating web pages and other information to be displayed in a web browser. Questions regarding HTML should include a minimal reproducible example and some idea of what you're trying to achieve. This tag is rarely used alone and is often paired with CSS and JavaScript.

Filter by
Sorted by
Tagged with
8696 votes
9 answers
742k views

Why does HTML think “chucknorris” is a color?

Why do certain random strings produce colors when entered as background colors in HTML? For example, bgcolor="chucknorris" produces a red background: <body bgcolor="chucknorris"> ...
user456584's user avatar
  • 86.6k
5476 votes
79 answers
4.6m views

How can I validate an email address in JavaScript?

I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...
5150 votes
68 answers
4.8m views

How do I check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery. For example, if the age checkbox is checked, then I need to show a textbox to enter ...
5046 votes
131 answers
4.8m views

How can I horizontally center an element?

How can I horizontally center a <div> within another <div> using CSS? <div id="outer"> <div id="inner">Foo foo</div> </div>
4410 votes
56 answers
2.5m views

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.? ...
4353 votes
42 answers
2.0m views

Change an HTML input's placeholder color with CSS

Chrome v4 supports the placeholder attribute on input[type=text] elements (others probably do too). However, the following CSS doesn't do anything to the placeholder's value: input[placeholder], [...
3675 votes
19 answers
2.7m views

Set cellpadding and cellspacing in CSS?

In an HTML table, the cellpadding and cellspacing can be set like this: <table cellspacing="1" cellpadding="1"> How can the same be accomplished using CSS?
kokos's user avatar
  • 43.1k
3380 votes
34 answers
3.4m views

How can I change an element's class with JavaScript?

How can I change the class of an HTML element in response to an onclick or any other events using JavaScript?
Nathan Smith's user avatar
  • 36.9k
3239 votes
22 answers
1.8m views

How do I disable the resizable property of a textarea?

I want to disable the resizable property of a textarea. Currently, I can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse. How can I disable this?
user549757's user avatar
3199 votes
103 answers
1.4m views

How do you disable browser autocomplete on web form field / input tags?

How do you disable autocomplete in the major browsers for a specific input (or form field)?
Brett Veenstra's user avatar
3157 votes
20 answers
291k views

Is it possible to apply CSS to half of a character?

What I am looking for: A way to style one HALF of a character. (In this case, half the letter being transparent) What I have currently searched for and tried (With no luck): Methods for styling ...
SimplyAzuma's user avatar
  • 25.3k
3052 votes
40 answers
2.5m views

How can I know which radio button is selected via jQuery?

I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery? I can get all of them like this: $("form :radio") How do I know which one is selected?
juan's user avatar
  • 80.4k
3048 votes
24 answers
1.4m views

How to store objects in HTML5 localStorage/sessionStorage

I'd like to store a JavaScript object in HTML5 localStorage, but my object is apparently being converted to a string. I can store and retrieve primitive JavaScript types and arrays using localStorage, ...
Kristopher Johnson's user avatar
2985 votes
21 answers
2.0m views

How do I modify the URL without reloading the page?

Is there a way I can modify the URL of the current page without reloading the page? I would like to access the portion before the # hash if possible. I only need to change the portion after the domain,...
Robin Rodricks's user avatar
2885 votes
16 answers
2.4m views

I need an unordered list without any bullets

I have created an unordered list. I feel the bullets in the unordered list are bothersome, so I want to remove them. Is it possible to have a list without bullets?
praveenjayapal's user avatar
2734 votes
37 answers
4.2m views

How do I vertically center text with CSS? [duplicate]

I have a <div> element which contains text and I want to align the contents of this <div> vertically center. Here is my <div> style: #box { height: 170px; width: 270px; ...
Irakli Lekishvili's user avatar
2705 votes
42 answers
1.8m views

Make a div fill the height of the remaining screen space

I am working on a web application where I want the content to fill the height of the entire screen. The page has a header, which contains a logo, and account information. This could be an arbitrary ...
Vincent McNabb's user avatar
2654 votes
42 answers
2.7m views

How to make a div 100% height of the browser window

I have a layout with two columns - a left div and a right div. The right div has a grey background-color, and I need it to expand vertically depending on the height of the user's browser window. Right ...
mike's user avatar
  • 26.6k
2646 votes
35 answers
9.4m views

How do I create an HTML button that acts like a link?

How do I create an HTML button that acts like a link? So that clicking the button redirects the user to a page. I want it to be accessible, and with minimal extra characters or parameters in the URL.
Andrew's user avatar
  • 228k
2521 votes
29 answers
1.6m views

How do I reduce the opacity of an element's background using CSS?

Is it possible, using CSS only, to make the background of an element semi-transparent but have the content (text & images) of the element opaque? I'd like to accomplish this without having the ...
Stijn Sanders's user avatar
2487 votes
44 answers
1.9m views

How can I make a div not larger than its contents?

I have a layout similar to: <div> <table> </table> </div> I would like for the div to only expand to as wide as my table becomes.
user avatar
2423 votes
21 answers
2.1m views

Get the size of the screen, current web page and browser window

How can I get windowWidth, windowHeight, pageWidth, pageHeight, screenWidth, screenHeight, pageX, pageY, screenX, screenY which will work in all major browsers?
turtledove's user avatar
  • 25.5k
2300 votes
31 answers
473k views

How do you parse and process HTML/XML in PHP?

How can one parse HTML/XML and extract information from it?
2279 votes
27 answers
547k views

HTML: Valid id attribute values?

When creating the id attributes for HTML elements, what rules are there for the value?
Mr Shark's user avatar
  • 26.1k
2273 votes
14 answers
1.1m views

How can I select an element with multiple classes in jQuery?

I want to select all the elements that have the two classes a and b. <element class="a b"> So, only the elements that have both classes. When I use $(".a, .b") it gives me the union, but I ...
Mladen's user avatar
  • 25.6k
2256 votes
32 answers
2.3m views

Retrieve the position (X,Y) of an HTML element

I want to know how to get the X and Y position of HTML elements such as img and div in JavaScript.
user avatar
2239 votes
26 answers
1.6m views

Vertically align text next to an image?

Why won't vertical-align: middle work? And yet, vertical-align: top does work. span{ vertical-align: middle; } <div> <img src="https://via.placeholder.com/30" alt="small img" /> ...
sam's user avatar
  • 23k
2211 votes
36 answers
3.7m views

RegEx match open tags except XHTML self-contained tags

I need to match all of these opening tags: <p> <a href="foo"> But not these: <br /> <hr class="foo" /> I came up with this and wanted to make sure I've got it right. I am ...
2201 votes
18 answers
1.7m views

HTML 5: Is it <br>, <br/>, or <br />?

I've tried checking other answers, but I'm still confused — especially after seeing W3schools HTML 5 reference. I thought HTML 4.01 was supposed to "allow" single-tags to just be <img> and <...
2066 votes
33 answers
3.6m views

How to auto-resize an image while maintaining aspect ratio

How do you auto-resize a large image so that it will fit into a smaller width div container whilst maintaining its width:height ratio? Example: stackoverflow.com - when an image is inserted onto the ...
001's user avatar
  • 62.9k
1996 votes
42 answers
2.4m views

How do I make a placeholder for a 'select' box?

I'm using placeholders for text inputs which is working out just fine. But I'd like to use a placeholder for my selectboxes as well. Of course I can just use this code: <select> <option ...
Thomas's user avatar
  • 20.8k
1934 votes
34 answers
3.7m views

How can I set the default value for an HTML <select> element?

I thought that adding a "value" attribute set on the <select> element below would cause the <option> containing my provided "value" to be selected by default: <select name="hall" ...
Jichao's user avatar
  • 40.5k
1907 votes
16 answers
1.4m views

How to move an element into another element

I would like to move one DIV element inside another. For example, I want to move this (including all children): <div id="source"> ... </div> into this: <div id="...
Mark Richman's user avatar
1881 votes
21 answers
808k views

Where should I put <script> tags in HTML markup?

When embedding JavaScript in an HTML document, where is the proper place to put the <script> tags and included JavaScript? I seem to recall that you are not supposed to place these in the <...
mipadi's user avatar
  • 400k
1879 votes
17 answers
683k views

<button> vs. <input type="button" />. Which to use?

When looking at most sites (including SO), most of them use: <input type="button" /> instead of: <button></button> What are the main differences between the two, if any? Are ...
Aron Rotteveel's user avatar
1878 votes
40 answers
1.2m views

How to align checkboxes and their labels consistently cross-browsers

This is one of the minor CSS problems that plague me constantly. How do folks around Stack Overflow vertically align checkboxes and their labels consistently cross-browser? Whenever I align them ...
1866 votes
10 answers
2.2m views

Vanilla JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it [duplicate]

With jQuery, we all know the wonderful .ready() function: $('document').ready(function(){}); However, let's say I want to run a function that is written in standard JavaScript with no library ...
chris's user avatar
  • 36.2k
1851 votes
9 answers
1.7m views

What does enctype='multipart/form-data' mean?

What does enctype='multipart/form-data' mean in an HTML form and when should we use it?
EBAG's user avatar
  • 21.7k
1844 votes
42 answers
2.7m views

Hide scroll bar, but while still being able to scroll

I want to be able to scroll through the whole page, but without the scrollbar being shown. In Google Chrome it's: ::-webkit-scrollbar { display: none; } But Mozilla Firefox and Internet ...
Oussama el Bachiri's user avatar
1813 votes
24 answers
3.5m views

How to redirect one HTML page to another on load

Is it possible to set up a basic HTML page to redirect to another page on load?
chobo's user avatar
  • 31.6k
1721 votes
30 answers
955k views

How Can I add HTML And CSS Into PDF [closed]

I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML. I'm now after a way of converting it to PDF. I have tried:...
1718 votes
12 answers
1.5m views

What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?

What's the difference if one web page starts with <!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> and If page starts with <!...
Morgan Cheng's user avatar
  • 74.1k
1651 votes
8 answers
1.2m views

<meta charset="utf-8"> vs <meta http-equiv="Content-Type">

In order to define charset for HTML5 Doctype, which notation should I use? Short: <meta charset="utf-8" /> Long: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
CuriousMind's user avatar
  • 33.6k
1647 votes
49 answers
1.8m views

How can I vertically center a div element for all browsers using CSS?

I want to center a div vertically with CSS. I don't want tables or JavaScript, but only pure CSS. I found some solutions, but all of them are missing Internet Explorer 6 support. <body> <...
Burak Erdem's user avatar
  • 19.6k
1643 votes
24 answers
2.0m views

Creating a div element in jQuery [duplicate]

How do I create a div element in jQuery?
useranon's user avatar
  • 29.3k
1629 votes
25 answers
2.1m views

How do I style a <select> dropdown with only CSS?

Is there a CSS-only way to style a <select> dropdown? I need to style a <select> form as much as humanly possible, without any JavaScript. What are the properties I can use to do so in ...
Jitendra Vyas's user avatar
1556 votes
34 answers
2.3m views

How do I vertically align text in a div?

I am trying to find the most effective way to align text with a div. I have tried a few things and none seem to work. .testimonialText { position: absolute; left: 15px; top: 15px; ...
shinjuo's user avatar
  • 20.5k
1520 votes
15 answers
2.2m views

How can I select an element by name with jQuery?

I have a table column I’m trying to expand and hide. jQuery seems to hide the <td> elements when I select it by class but not by the element’s name. For example: $(".bold").hide(); // ...
T.T.T.'s user avatar
  • 33.4k
1513 votes
12 answers
163k views

Why don't self-closing script elements work?

What is the reason browsers do not correctly recognize: <script src="foobar.js" /> <!-- self-closing script element --> Only this is recognized: <script src="foobar.js"></...
dimarzionist's user avatar
  • 18.5k
1479 votes
27 answers
2.6m views

Check if checkbox is checked with jQuery

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array? I am using the following code, but it always returns the count of checked checkboxes regardless of id. ...
Jake's user avatar
  • 25.5k

1
2 3 4 5
23633