DEV Community

Ajinkgupta
Ajinkgupta

Posted on

2023 HTML Tutorial: From Basic to Advanced

I. Introduction

2023 HTML Tutorial: From Basic to Advanced

HTML (Hypertext Markup Language) is the standard markup language used to create web pages.

HTML defines the structure and content of a web page using a set of markup tags and attributes. Each HTML tag represents a different part of the page, such as headings, paragraphs, images, links, and forms. Attributes provide additional information about each tag, such as the source of an image or the URL of a link.

HTML documents are composed of two main parts: the head section and the body section. The head section contains metadata about the document, such as the page title and description, while the body section contains the actual content of the page.

HTML has evolved through several versions since its inception in 1991 by Tim Berners-Lee, the inventor of the World Wide Web. The most recent version of HTML is HTML5, which introduced new features and improvements for web development.

As a beginner in web development, it’s important to have a good understanding of the basics of HTML in order to create effective and accessible web pages. In the following sections, we will explore the main concepts and terminology used in HTML and provide an overview of the different HTML versions.

II. HTML Documents

HTML documents consist of a set of markup tags and attributes that define the structure and content of a web page. In this section, we will cover the basic components of an HTML document.

  1. Document structure: An HTML document has a hierarchical structure, with each tag nested inside another tag. The top-level tag is the <html> tag, which contains two main sections: the head section and the body section. The head section contains metadata about the document, such as the page title and description, while the body section contains the actual content of the page.
  2. Document type declaration: The document type declaration (DTD) is a special tag that appears at the beginning of an HTML document and tells the web browser which version of HTML the document is written in. The current standard is HTML5, so the DTD for an HTML5 document looks like this: <!DOCTYPE html>
  3. HTML tags: HTML tags are used to define the structure and content of a web page. Tags are enclosed in angle brackets (<>) and usually come in pairs, with an opening tag and a closing tag. The content of the tag goes between the opening and closing tags. For example, the <p> tag is used to define a paragraph, and looks like this: <p>This is a paragraph.</p>
  4. Head and body sections: As mentioned earlier, an HTML document has two main sections: the head section and the body section. The head section contains metadata about the document, such as the page title and description, and is enclosed in the <head> tag. The body section contains the actual content of the page and is enclosed in the <body> tag.
  5. Comments: HTML comments are used to add notes and explanations to the code, and are not displayed in the web page. Comments are enclosed in the <!– –> tags. For example, <!– This is a comment –>.

Understanding the structure of an HTML document is important for creating well-formed and accessible web pages. The next sections will cover HTML tags in more detail, including basic tags for text formatting, links, images, and tables.

III. HTML Tags

HTML tags are used to define the structure and content of a web page. In this section, we will cover the different types of HTML tags, including basic tags for text formatting, links, images, and tables, as well as block-level and inline tags, semantic HTML tags, and empty tags.

  1. Basic HTML tags: Some of the most commonly used HTML tags include:
  • <p>: defines a paragraph of text
  • <a>: defines a hyperlink to another page or resource
  • <img>: defines an image to be displayed on the page
  • <ul>/<ol>: defines an unordered or ordered list
  • <table>: defines a table to be displayed on the page
  • <form>: defines a form for user input
  1. Block-level and inline tags: HTML tags can be classified as either block-level or inline tags, depending on how they affect the layout of the page. Block-level tags create a new block of content that takes up the entire width of its parent container, while inline tags are used to wrap smaller portions of content within a larger block. Some examples of block-level tags include <p>, <div>, and <h1>-<h6>, while inline tags include <span>, <a>, and <img>.
  2. Semantic HTML tags: Semantic HTML tags are used to give meaning to the content of the page, making it easier for search engines and assistive technologies to understand the structure and purpose of the content. Some examples of semantic HTML tags include:
  • <header>: defines the header section of a page
  • <nav>: defines the navigation links of a page
  • <section>: defines a section of the page
  • <article>: defines an article or blog post
  • <footer>: defines the footer section of a page
  1. Empty tags: Empty tags, also known as void or self-closing tags, do not require a closing tag because they do not contain any content. Some examples of empty tags include <img>, <br>, and <input>.

Understanding the different types of HTML tags is essential for creating well-structured and semantically meaningful web pages. The next sections will cover HTML attributes, including those used for styling and accessibility.

 

IV. Text Formatting

HTML tags can be used to format text in a variety of ways. In this section, we will cover some of the most commonly used text formatting tags, including heading tags, paragraph tags, and list tags.

  1. Text formatting tags: HTML tags can be used to add emphasis or highlight text in different ways. Some commonly used text formatting tags include:
  • <b>: defines bold text
  • <i>: defines italicized text
  • <u>: defines underlined text
  • <em>: defines emphasized text
  • <strong>: defines strongly emphasized text
  1. Heading tags: Heading tags are used to define the headings and subheadings of a web page. There are six different levels of heading tags, from <h1> for the main title to <h6> for the smallest subheading.
  2. Paragraphs and line breaks: The <p> tag is used to define a paragraph of text. Multiple paragraphs can be separated by a line break using the <br> tag.
  3. Lists: HTML supports two types of lists: ordered lists, which use numbers or letters to sequence items, and unordered lists, which use bullet points. The <ul> and <ol> tags are used to define unordered and ordered lists, respectively, and the <li> tag is used to define individual list items.

Understanding text formatting tags is important for creating visually appealing and readable web pages. The next sections will cover HTML attributes, including those used for adding links and images to a web page.

V. Links and Images

Links and images are important elements of a web page, and HTML provides specific tags and attributes for creating them. In this section, we will cover how to create links and images in HTML, and how to customize their attributes.

  1. Creating links with the <a> tag: The <a> tag is used to create hyperlinks to other pages or resources on the web. To create a link, we use the href attribute to specify the URL of the page or resource we want to link to. For example:
 <a href="https://www.example.com">Link text</a>
  1. Linking to internal and external pages: Links can be used to navigate within a website or to link to external resources. To link to an internal page, we can use a relative URL, which specifies the path to the page from the current page. To link to an external resource, we use the full URL. For example:
 <a href="/about.html">About Us</a>
<a href="https://www.example.com">External link</a>
  1. Creating image tags with <img>: The <img> tag is used to display images on a web page. We use the src attribute to specify the URL of the image file we want to display. For example:
 <img src="image.jpg" alt="Image description">
  1. Image attributes: In addition to the src attribute, the <img> tag supports several other attributes that can be used to customize the display of the image, including alt, width, height, and title. The alt attribute is used to provide a text description of the image for accessibility purposes, while the width and height attributes can be used to resize the image. For example:
 <img src="image.jpg" alt="Image description" width="500" height="300" title="Image title">

Understanding how to create links and images is important for creating engaging and interactive web pages. The next section will cover how to create tables in HTML.

 

VI. Tables

Tables are a useful way to display data in a structured format on a web page. In this section, we will cover how to create tables in HTML, including adding rows and columns, headers, and cell content.

  1. Creating tables with <table>: To create a table in HTML, we use the <table> tag. Within the <table> tag, we can define rows using the <tr> tag, and cells within each row using the <td> tag. For example:
 <table>
  <tr>
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  </tr>
  <tr>
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 2</td>
  </tr>
</table>
  1. Table rows and cells: Table rows are defined using the <tr> tag, while table cells are defined using the <td> tag. Each row can contain a different number of cells, depending on the number of columns in the table.
  2. Table headers with <th>: To add headers to a table, we use the <th> tag instead of <td>. Header cells are bolded and centered by default. For example:
 <table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  </tr>
  <tr>
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 2</td>
  </tr>
</table>
  1. Table data with <td>: The <td> tag is used to define regular data cells in a table.
  2. Spanning rows and columns: Sometimes we want a cell to span multiple rows or columns. For this purpose, we can use the rowspan and colspan attributes of the <td> and <th> tags. For example:
 <table>
  <tr>
    <th rowspan="2">Header 1</th>
    <th colspan="2">Header 2</th>
  </tr>
  <tr>
    <td>Row 1, Cell 2</td>
    <td>Row 1, Cell 3</td>
  </tr>
  <tr>
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 2</td>
    <td>Row 2, Cell 3</td>
  </tr>
</table>

Understanding how to create tables is important for displaying data on a web page in an organized and easy-to-read format. The next section will cover how to use forms in HTML.

VII. Forms

Forms are an essential part of web development, allowing users to input data and interact with a website. In this section, we will cover how to create forms in HTML, including input fields, radio buttons, checkboxes, and dropdown lists.

  1. Creating forms with <form>: To create a form in HTML, we use the <form> tag. Within the <form> tag, we can add various form elements, such as input fields, radio buttons, and checkboxes.
 <form>
  <!-- form elements go here -->
</form>
  1. Text input fields: Text input fields allow users to enter text data into a form. We can create a text input field using the <input> tag with the type attribute set to “text”.
 <label for="username">Username:</label>
<input type="text" id="username" name="username">
  1. Radio buttons and checkboxes: Radio buttons and checkboxes allow users to select one or more options from a list. We can create radio buttons and checkboxes using the <input> tag with the type attribute set to “radio” and “checkbox”, respectively.
<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label>

<label for="newsletter">Subscribe to our newsletter:</label>
<input type="checkbox" id="newsletter" name="newsletter" value="yes">
  1. Dropdown lists with <select> and <option>: Dropdown lists allow users to select one option from a list of options. We can create a dropdown list using the <select> tag with <option> tags for each option.
 <label for="country">Country:</label>
<select id="country" name="country">
  <option value="USA">USA</option>
  <option value="Canada">Canada</option>
  <option value="Mexico">Mexico</option>
</select>
  1. Submitting forms with <button> and <input>: To submit a form, we can use the <button> or <input> tags with the type attribute set to “submit”.
<button type="submit">Submit</button>

<input type="submit" value="Submit">

Understanding how to create forms in HTML is essential for building interactive websites. The next section will cover how to add multimedia to web pages using audio and video tags.

 

VIII. Multimedia

Multimedia elements, such as audio, video, and images, can enhance the user experience on a website. In this section, we will cover how to embed audio and video files using HTML tags, as well as how to work with iframes to display external content.

  1. Embedding videos with <video>: To embed a video on a web page, we can use the <video> tag. Within the <video> tag, we can add attributes such as “src” to specify the URL of the video file, and “controls” to enable playback controls.
 <video src="video.mp4" controls></video>
  1. Embedding audio with <audio>: To embed audio on a web page, we can use the <audio> tag. Within the <audio> tag, we can add attributes such as “src” to specify the URL of the audio file, and “controls” to enable playback controls.
 <audio src="audio.mp3" controls></audio>
  1. Working with iframes: An iframe is an HTML tag that allows us to display external content, such as a web page, within our own web page. We can create an iframe using the <iframe> tag, with the “src” attribute set to the URL of the external content.
 <iframe src="https://www.example.com"></iframe>

Understanding how to work with multimedia elements and iframes is important for creating dynamic and engaging web pages. The next section will cover how to style HTML elements using CSS.

IX. CSS

CSS, or Cascading Style Sheets, is a powerful tool for styling HTML elements. In this section, we will cover the basics of CSS, including how to apply CSS styles to HTML elements, the different ways to include CSS in an HTML document, and the various CSS selectors and properties that can be used to style web pages.

  1. Introduction to CSS: CSS allows us to define how HTML elements should be displayed on a web page, including their font size and style, color, and positioning. CSS styles can be applied to individual elements, or to groups of elements, allowing us to create consistent and visually appealing web pages.
  2. Applying CSS styles to HTML elements: CSS styles can be applied to HTML elements using various CSS selectors, such as element selectors, class selectors, and ID selectors. We can set properties such as font size, color, background color, and border styles using CSS.
/* Set the font size of all paragraphs to 16px */
p {
  font-size: 16px;
}

/* Set the background color of all elements with the class "highlight" to yellow */
.highlight {
  background-color: yellow;
}

/* Set the font color of the element with the ID "title" to blue */
#title {
  color: blue;
}
  1. Inline, internal, and external CSS: CSS styles can be included in an HTML document in three ways: inline, internal, and external. Inline styles are applied directly to an HTML element using the “style” attribute, while internal styles are defined within the <head> section of an HTML document using the <style> tag. External styles are defined in a separate CSS file, and linked to the HTML document using the <link> tag.
 <!-- Inline CSS -->
<p style="font-size: 16px;">This paragraph has a font size of 16px.</p>

<!-- Internal CSS -->
<head>
  <style>
    p {
      font-size: 16px;
    }
  </style>
</head>

<!-- External CSS -->
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
  1. CSS selectors and properties: CSS selectors allow us to target specific HTML elements and apply styles to them. We can use element selectors to target specific HTML elements, class selectors to target elements with a specific class, and ID selectors to target elements with a specific ID. CSS properties, such as font-size and background-color, allow us to set the styles for targeted elements.
 /* Target all paragraphs */
p {
  font-size: 16px;
  color: #333;
}

/* Target all elements with the class "highlight" */
.highlight {
  background-color: yellow;
}

/* Target the element with the ID "title" */
#title {
  font-size: 24px;
  color: blue;
}

Understanding how to use CSS to style HTML elements is essential for creating visually appealing and functional web pages. The next section will cover advance html.

X. Advanced HTML Topics

In addition to the basics of HTML, there are several advanced topics that are important for web developers to understand. In this section, we will cover some of these topics, including HTML5 features, accessibility, semantic elements, and responsive web design.

  1. HTML5 features: HTML5 is the latest version of HTML, and includes several new features that make it easier to develop rich, interactive web applications. Some of these features include the canvas element for creating graphics, web storage for storing data on the client-side, and new video and audio elements for embedding media in web pages.
<!-- Create a canvas element -->
<canvas id="myCanvas"></canvas>

<!-- Use web storage to store data -->
<script>
  localStorage.setItem("name", "John");
  var name = localStorage.getItem("name");
  console.log(name); // Outputs "John"
</script>

<!-- Embed a video -->
<video src="myvideo.mp4" controls></video>
  1. Accessibility in HTML: Accessibility is an important consideration when designing web pages, as it ensures that all users, including those with disabilities, can access and use the content. HTML provides several features for making web pages more accessible, such as the alt attribute for images, the title attribute for links, and the use of semantic HTML to provide structure to the content.
 <!-- Use the alt attribute to provide a description for images -->
<img src="myimage.jpg" alt="A cat sitting on a windowsill">

<!-- Use the title attribute to provide additional information for links -->
<a href="https://www.example.com" title="Visit Example.com">Example</a>

<!-- Use semantic HTML to provide structure to the content -->
<header>
  <h1>My Website</h1>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
</header>
  1. HTML5 semantic elements: HTML5 introduces several new semantic elements, such as <header>, <footer>, <article>, and <aside>, which provide more meaningful and descriptive markup for web pages. These elements help search engines and screen readers to better understand the content of a web page, and can also make it easier to style and structure the page using CSS.
 <header>
  <h1>My Website</h1>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
</header>

<main>
  <article>
    <h2>Article Title</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  </article>
  <aside>
    <h3>Related Articles</h3>
    <ul>
      <li><a href="#">Article 1</a></li>
      <li><a href="#">Article 2</a></li>
      <li><a href="#">Article 3</a></li>
    </ul>
  </aside>
</main>

<footer>
  <p>&copy; 2023 My Website</p>
</footer>
  1. Responsive web design with HTML: Responsive web design is the practice of creating web pages that can adapt to different screen sizes and devices, such as mobile phones and tablets. HTML provides several features for creating responsive web pages, such as the viewport meta tag, which allows web pages to adjust to the width of the device screen, as well as media queries, which can be used to apply different CSS styles depending on the device screen size and orientation.

Other HTML features that can be used for responsive web design include:

  1. Flexible images and media: HTML allows you to specify the maximum width of images and media, which can help them adjust to different screen sizes.
  2. Fluid layouts: By using percentage-based widths and flexible containers, you can create layouts that adjust to different screen sizes.
  3. Responsive typography: HTML provides several features for creating responsive typography, such as the viewport units (vw, vh), which allow font sizes to adjust to the device screen size.

Overall, responsive web design with HTML is an essential practice for creating websites that work well on different devices and screen sizes.

XI. Best Practices and Standards

HTML coding standards and conventions:

  • Consistency is key when it comes to HTML coding standards and conventions. It’s important to use the same naming conventions and formatting styles throughout your HTML code to make it easy to read and maintain.
  • Use semantic HTML tags to give meaning to the content on your website. This helps search engines and screen readers better understand your website’s content.
  • Indent your code properly to make it easier to read and follow the structure of your HTML document.

Validating HTML code:

  • Validating your HTML code means checking that it follows the rules and syntax specified in the HTML standard. This helps ensure that your website is compatible with different web browsers and devices.
  • There are several online tools you can use to validate your HTML code, such as the W3C Markup Validation Service.

SEO considerations in HTML:

  • Search engine optimization (SEO) is the practice of optimizing your website to rank higher in search engine results pages (SERPs). HTML plays an important role in SEO.
  • Use descriptive and relevant page titles and meta descriptions to help search engines and users understand what your website is about.
  • Use proper heading tags (h1, h2, h3) to organize your content and help search engines understand the structure of your website.
  • Use alt tags for images to provide descriptions for users who are visually impaired or for when the image fails to load.
  • Avoid using too many nested tables, as they can make it difficult for search engines to crawl your website and understand its structure.

Top comments (0)