HTML documents are made up of elements and tags. An HTML element can be a simple tag or a tag with content inside of it. Each element tells the browser how to render content on a webpage.
HTML elements are the building blocks of an HTML page. An element consists of an opening tag, content, and a closing tag.
<
: Paragraphp
><
toh1
><
: Headings (h1 is the largest, h6 is the smallest)h6
><
: Anchor (hyperlink)a
><
: Imageimg
><
: Unordered Listul
><
: Ordered Listol
><
: List Itemli
>
HTML attributes provide additional information about HTML elements. Attributes are always written inside the opening tag of an element.
<
: Unique identifier for an elementid
><
: Specifies one or more classes for an elementclass
><
: Specifies the source of an imagesrc
><
: Specifies the URL for a hyperlinkhref
><
: Provides alternative text for an imagealt
>
Every HTML document follows a basic structure. Here’s an overview of how it looks:
- DOCTYPE declaration: Specifies the document type (e.g.,
<
)!DOCTYPE html
> - HTML element: The root element that wraps all content (
<
)html
> - Head element: Contains meta-information like the character set, title, and link to stylesheets (
<
)head
> - Body element: Contains the content that appears on the webpage (
<
)body
>
HTML provides various ways to work with text and links on a webpage.
- Bold:
<
orb
><
strong
> - Italic:
<
ori
><
em
> - Underline:
<
u
>
Use the <
tag to create hyperlinks.a
>
Forms (<
) are used to collect user input. A form can contain input fields (e.g., form
><
, text
><
, checkbox
><
), labels, and submit buttons.password
>
HTML also allows you to embed media such as images (<
), audio (img
><
), and video (audio
><
).video
>
Here are some best practices to follow when writing HTML:
- Use semantic elements: Elements like
<
,header
><
,footer
><
, andarticle
><
provide meaning to your content and help with accessibility.section
> - Structure your code properly: Use indentation and spacing to make your HTML readable.
- Avoid inline styles: Instead, use external CSS for styling.