Previous Next

HTML Attributes

HTML attributes are pieces of information that accompany HTML elements to add additional information or functionality. An attribute of an HTML element is declared by an opening tag, and it is made up of a name and a value separated by an equals sign (=) and double quotes ("").

src Attribute

The src attribute gives the URL of an external resource, like an image or a script.

Example:

<img src="little_boy.jpg">

Output

src_attribute output image

href Attribute

The href attribute defines the URL of the destination of the link, employed with the <a> tag.

Example:

<a href=""> Visit my website </a>

Output

href_attribute output image

width and height Attributes

The width and height attribute is employed to define the width and height of an image.

Example:

 <img src="little_boy.jpg" width="400" height="400">

alt Attribute

The alt attributes show alternative text for elements, such as if the picture fails to load.

Example:

 <img src="little_boy.jpg" alt="A boy with camera">

Output

alt_attribute output image

id Attribute

The ID attribute is employed to give a unique identifier to an element in the HTML document.

Example:

<p> This is a paragraph </p>

Title Attribute

The title attribute specifies additional information for an element. It is often shown as a tooltip when the user puts the mouse over the element.

Example:

<p> This is a paragraph </p>

Output

Style Attribute

The style attribute allows you to set inline CSS styles for an element directly from the HTML.

Example:

<h1 style="background-color:aqua; color:white;"> This is a heading </h1>
<p style="background-color:aquamarine; color:red;"> This is a paragraph </p>

Output

style attribute output image
Previous Next