loader image

HTML Attributes

In this page

In this tutorial, we will learn about attributes in HTML.

Attributes are used to provide additional information about the HTML elements. They can be found on the opening tag of the element. HTML attributes usually come with two parts: a name and a value separated by an equal sign.

HTML attributes
HTML Attributes

The attribute name shows the type of additional information we are going to provide about the element. It is written in lowercase. The value is the information for the attribute and should be surrounded by double quotations.

Most attributes can only be used on specific elements, however, a few can appear on any element. Some of the common HTML attributes are discussed below.

align

The align attribute specifies how the element and its contents are placed in a window. It usually takes a value of left, right, or center.

For example,

<p align="center">The quick, brown fox jumps over a lazy dog.</p>
Output

The quick, brown fox jumps over a lazy dog.

color

The color attribute is used to set the colour of the text. Value of color attribute can be specified either by a browser-dependent named colour like red or by the hexadecimal #RRGGBB format.

For example,

<font color="#ff0000">The quick, brown fox jumps over a lazy dog.</p>
Output

The quick, brown fox jumps over a lazy dog.

bgcolor

The bgcolor attribute sets the background colour for the document. The colour can be specified either by a browser-dependent named colour like blue or by the hexadecimal #RRGGBB format.

Usage,

<body bgcolor="red">

</body>

border

The border attributes set the border width for a table. The width in pixels is given as the value for this attribute.

Usage,

<table border="1">    </table>

size

The size attribute is used with the <input> and <select> elements. For input elements, it sets the visible width, in characters. For select elements, it sets the number of visible options in a drop-down list.

Usage,

<form>
    <input type="text" size="35"><br>
    <select size="3">
       <option>Volvo</option>
       <option>Saab</option>
       <option>Opel</option>
       <option>Audi</option>
    </select>
</form>
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top