HTML Attributes

HTML Basic Examples

Explore the fundamental elements of HTML with these examples.

HTML Attributes

All HTML elements can have attributes, providing additional information about elements. Attributes are always specified in the start tag.

The href Attribute

The href attribute is used with the <a> (anchor) tag to specify the URL of the linked page.

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

The src Attribute

The src attribute is used with the <img> tag to specify the source (URL) of the image.

<img src="image.jpg" alt="An example image">

Absolute URL

An absolute URL provides the complete web address, including the protocol (http or https).

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

Relative URL

A relative URL specifies the path to the linked file relative to the current page.

<a href="/pages/about.html">About Us</a>

The width and height Attributes

The width and height attributes define the dimensions of an image in pixels.

<img src="image.jpg" alt="An example image" width="300" height="200">

The alt Attribute

The alt attribute provides alternative text for images, useful for accessibility.

<img src="image.jpg" alt="An example image">

The style Attribute

The style attribute is used to apply inline CSS styles to an element.

<p style="color: blue; font-size: 16px;">Styled Paragraph</p>

The lang Attribute

The lang attribute specifies the language of the content within an element.

<html lang="en">...</html>

The title Attribute

The title attribute provides additional information about an element when hovered over.

<a href="#" title="Go to Home">Home</a>

HTML Documents

HTML documents are the building blocks of web pages, defining the structure and content.

The <!DOCTYPE> Declaration

The <!DOCTYPE> declaration defines the type and version of the HTML document.

<!DOCTYPE html>

HTML Headings

HTML provides six levels of headings, from <h1> to <h6>.

<h1>This is Heading 1</h1>

HTML Paragraphs

Paragraphs structure and separate content into readable blocks.

<p>This is a paragraph.</p>

HTML Images

Images are displayed using the <img> tag.

<img src="image.jpg" alt="An example image">

How to View HTML Source

View HTML source code by pressing CTRL + U or right-clicking on the page and selecting "View Page Source."

Continue your web development journey with HTML. It's an exciting learning experience!

© 2023 Your Website. All rights reserved.