DEV Community

Kavya
Kavya

Posted on • Originally published at sites.google.com

What is HTML?

At its core, HTML is the language of the web. It's not a programming language in the sense that it doesn't have complex logic or algorithms. Instead, it's a markup language. Think of it as a way to structure and label the content you see on a website. It's the foundation upon which websites are built.

Imagine building a house. HTML is like the framework – the walls, the floors, and the roof. It provides the basic structure, but doesn't add the color, the style, or the interactivity. For that, you need other technologies like CSS (for styling) and JavaScript (for interactivity).

Key Concepts

  1. Elements: HTML is made up of elements. An element is a component of a webpage, such as a paragraph, a heading, an image, a link, or a button. Each element has a specific purpose and structure.
  • Tags: Elements are defined using tags. Tags are keywords enclosed in angle brackets (< and >). Most elements have an opening tag (e.g., <h1>) and a closing tag (e.g., </h1>).
  • Content: The content of an element goes between its opening and closing tags. For example, in the tag <h1>My Heading</h1>, the content is "My Heading."
  • Empty Elements: Some elements are empty elements. They don't have content and therefore don't have closing tags. A good example of this is the <img> tag, used for images.
  1. Structure of an HTML Document: Every HTML document follows a basic structure:
  • <!DOCTYPE html>: This declaration tells the browser that the document is an HTML5 document. It should always be the very first line in your HTML file.
  • <html>: This is the root element, encapsulating the entire HTML document. Everything else goes inside this element.
  • <head>: This section contains metadata about the HTML document. Metadata is information about the data, rather than the content itself. This can include the document's title, links to stylesheets, and other information that's not visible on the webpage.
    • <title>: Sets the title that appears in the browser tab or window title bar.
  • <body>: This section contains the actual content that will be displayed on the webpage. This includes everything from text and images to forms and tables.

A Basic HTML Document Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First HTML Page</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph of text. Here you will learn all about HTML.</p>
    <img src="my_image.jpg" alt="A description of my image">
    <a href="https://www.example.com">Visit Example Website</a>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Explanation of Elements Used:

  • <!DOCTYPE html>: As explained before, this is the document declaration.
  • <html lang="en">: The root element, with the attribute lang="en" indicating the language of the document is English.
  • <head>: The section for metadata.
    • <meta charset="UTF-8">: Specifies the character encoding for the document. UTF-8 is a common and widely supported character encoding.
    • <meta name="viewport" content="width=device-width, initial-scale=1.0">: This is important for responsive web design; it tells the browser how to control the page's dimensions and scaling on different devices.
    • <title>My First HTML Page</title>: The title that will appear in the browser tab.
  • <body>: The main content of the webpage.
    • <h1>Welcome to My Website</h1>: A level 1 heading (the most important heading). HTML offers different heading levels: <h1> to <h6>.
    • <p>This is a paragraph of text. Here you will learn all about HTML.</p>: A paragraph of text.
    • <img src="my_image.jpg" alt="A description of my image">: An image element. src is an attribute specifying the path to the image file. alt is an important attribute providing alternative text for accessibility; it is displayed if the image cannot be loaded.
    • <a href="https://www.example.com">Visit Example Website</a>: A hyperlink element. href is the attribute specifying the URL to link to. The content within the <a> tag is the clickable text for the link.

Common HTML Elements

Here's a look at some other important HTML elements:

  • Headings: <h1> to <h6> (as we saw earlier) are used to define different heading levels. <h1> is typically used for the most important heading on the page.
  • Paragraphs: <p> defines a paragraph of text.
  • Line Breaks: <br> inserts a single line break. (It's an empty element).
  • Horizontal Rules: <hr> creates a horizontal line. (It's an empty element).
  • Links: <a> (anchor tags) are used to create hyperlinks to other pages or other resources. The href attribute determines the link destination.
  • Images: <img> embeds images. The src attribute specifies the path to the image file, and the alt attribute provides alternative text for accessibility.
  • Lists:
    • Unordered Lists: <ul> creates an unordered list (typically with bullet points). Each list item is defined using <li>.
    • Ordered Lists: <ol> creates an ordered list (typically numbered). Each list item is defined using <li>.
  • Divisions and Spans:
    • <div>: A block-level container that's used to group content and is often used for creating layouts or sections.
    • <span>: An inline container used to group inline content, typically for styling purposes.
  • Forms:
    • <form>: Creates a form for collecting user input.
    • <input>: Creates form input fields (e.g., text fields, checkboxes, radio buttons).
    • <textarea>: Creates a multi-line text input area.
    • <button>: Creates a button (e.g., submit, reset).
  • Tables:
    • <table>: Creates a table.
    • <tr>: Defines a table row.
    • <th>: Defines a table header cell.
    • <td>: Defines a table data cell.

Attributes

You've seen attributes already, such as src, alt, href, and lang. Attributes provide additional information about HTML elements. They are always specified within the opening tag, like this: <element attribute1="value1" attribute2="value2">.

Best Practices and Accessibility

  • Use Semantic HTML: Use the correct HTML tags for their intended purpose. For example, use <article> for an article, <nav> for navigation, and <footer> for the footer. This not only helps with organization but also improves accessibility and search engine optimization (SEO).
  • Accessibility: Always include the alt attribute for images and ensure sufficient contrast between text and background colors to make your website usable for people with disabilities.
  • Clean Code: Indent your code correctly, and add comments to make it easier to read and maintain.
  • Valid HTML: Ensure your HTML code validates against the HTML standards. There are online validators that can help with this.

This introduction is just the beginning of your journey with HTML. To truly master it, practice writing code, experimenting with different elements, and reading more advanced documentation. Don't be afraid to get your hands dirty and try building your own simple web pages.

Top comments (1)

Collapse
 
devtostd profile image
Dev Studio