
HTML Tutorial for Beginners
Introduction to HTML
HTML, or Hypertext Markup Language, is the standard markup language used to create web pages. HTML code is used to structure content on a web page and to define the different elements that make up a page, such as headings, paragraphs, links, and images.
HTML is a markup language, which means that it consists of a series of tags that tell a web browser how to display content. Tags are enclosed in angle brackets, and most tags come in pairs, with an opening tag and a closing tag. The content that you want to display on a web page is placed between the opening and closing tags.
Here's an example of a basic HTML document:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>This is a paragraph of text.</p>
<a href="http://www.example.com">This is a link.</a>
</body>
</html>
This code creates a simple web page that displays a heading, a paragraph of text, and a link.
HTML Tags
HTML tags are used to define the different elements that make up a web page. Here are some of the most commonly used HTML tags:
<html>: The root element of an HTML page.
<head>: Contains metadata about the page, such as the page title and links to stylesheets.
<title>: Defines the title of the page, which is displayed in the browser's title bar.
<body>: Contains the main content of the page.
<h1> to <h6>: Defines headings of different sizes. <h1> is the largest heading, and <h6> is the smallest.
<p>: Defines a paragraph of text.
<a>: Defines a hyperlink.
<img>: Defines an image.
<ul> and <li>: Define an unordered list, where each item is marked with a bullet point.
<ol> and <li>: Define an ordered list, where each item is numbered.
HTML Attributes
HTML attributes provide additional information about an HTML element. Attributes are specified in the opening tag, and they are typically used to provide information such as the URL of a link or the source of an image.
Here are some common HTML attributes:
href: Specifies the URL of a link.
src: Specifies the URL of an image.
alt: Specifies alternative text for an image, which is displayed if the image cannot be loaded.
class: Specifies one or more class names for an element, which can be used to apply styles with CSS.
id: Specifies a unique identifier for an element, which can be used to target the element with JavaScript or CSS.
HTML Examples
Here are some examples of how to use HTML tags and attributes to create different types of content:
Headings
<h1>This is a level 1 heading</h1>
<h2>This is a level 2 heading</h2>
<h3>This is a level 3 heading</h3>
<h4>This is a level 4 heading</h4>
<h5>This is a level 5 heading</h5>
<h6>This is a level 6 heading</h6>
Paragraphs
<p>This is a paragraph of text. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Another paragraph of text.
Links
<a href="http://www.example.com">This is a link to Example.com</a>
Images
<img src="example.jpg" alt="An example image">
Lists
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
HTML Forms
HTML forms are used to collect user input on a web page. Forms can contain different types of input fields, such as text boxes, radio buttons, checkboxes, and drop-down lists. Here's an example of a basic HTML form:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age"><br>
<input type="submit" value="Submit">
</form>
This form contains several input fields, including a text field for the user's name, an email field, a password field, and a number field for the user's age. The submit button is used to submit the form data to a server.
Intermediate HTML
In addition to the basics covered in the previous section, there are several intermediate-level HTML concepts that can help you create more complex and dynamic web pages.
Tables
Tables are useful for presenting data in a structured format. Here's an example of a basic HTML table:
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Jane</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
This table contains a header row and two data rows, each with three columns. The thead element contains the header row, and the tbody element contains the data rows.
Forms with more input types
HTML forms can contain many different types of input fields, including checkboxes, radio buttons, drop-down lists, and more. Here's an example of a form with several input types:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age"><br>
<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><br>
<label for="interests">Interests:</label>
<select id="interests" name="interests[]" multiple>
<option value="music">Music</option>
<option value="sports">Sports</option>
<option value="books">Books</option>
<option value="movies">Movies</option>
</select><br>
<label for="terms">I agree to the terms and conditions:</label>
<input type="checkbox" id="terms" name="terms"><br>
<input type="submit" value="Submit">
</form>
In addition to the input types covered in the previous section, this form also contains radio buttons for the user's gender, a drop-down list for the user's interests, and a checkbox for agreeing to the terms and conditions.
Semantic HTML
Semantic HTML is the practice of using HTML elements that have a clear meaning and purpose, rather than generic elements like div and span. This can make your HTML code more readable and accessible to people who use screen readers or other assistive technology. Here are some examples of semantic HTML elements:
<article>
<h2>Article Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.</p>
</article>
<aside>
<h3>Related Links</h3>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</aside>
<footer>
<p>Copyright © 2023</p>
</footer>
In this example, we're using header for the page header, nav for the navigation links, main for the main content of the page, article for a specific article, aside for related links, and footer for the page footer.
Multimedia
HTML provides several ways to include multimedia content in your web pages, including images, audio, and video. Here are some examples:
<img src="example.jpg" alt="Example Image">
<audio controls>
<source src="example.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<video controls width="320" height="240">
<source src="example.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
In this example, we're including an image with an img element, an audio file with an audio element, and a video file with a video element. The controls attribute adds playback controls to the audio and video elements.
Advanced HTML
Finally, there are some advanced HTML concepts that you may need for more complex web pages and applications.
HTML5 APIs
HTML5 introduced several new APIs that allow you to build more interactive and responsive web pages. Some of the most popular HTML5 APIs include:
Geolocation API: allows web pages to access the user's location information
Canvas API: allows you to draw graphics and animations on a web page
Web Storage API: allows you to store data on the user's computer, even when they're offline
Web Workers API: allows you to run JavaScript code in the background, without blocking the main thread
To use these APIs, you'll need to write JavaScript code that interacts with them. Here's an example of using the Geolocation API:

Responsive Design
Responsive design is the practice of designing web pages that can adapt to different screen sizes and device types, including desktops, laptops, tablets, and smartphones. To create responsive designs, you can use a combination of HTML, CSS, and JavaScript.
One popular technique for responsive design is called media queries. Media queries allow you to apply different styles to a web page based on the size of the screen. Here's an example:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
@media only screen and (max-width: 600px) {
.header {
font-size: 30px;
}
}
</style>
</head>
<body>
<div class="header">
<h1>My Website</h1>
<p>A responsive website</p>
</div>
<div class="content">
<p>Welcome to my website!</p>
</div>
</body>
</html>
In this example, we're using a media query to apply a different font size to the header when the screen width is less than 600 pixels. This ensures that the header remains readable on smaller screens.
Accessibility
Finally, it's important to design web pages that are accessible to all users, including those with disabilities. HTML provides several features to make web pages more accessible, including:
Semantic HTML: using the appropriate HTML tags to indicate the structure and meaning of content
Alt text: providing descriptive text for images and other non-text content
ARIA attributes: adding additional information to HTML elements to help screen readers and other assistive technologies understand their purpose
Here's an example of using the alt attribute to provide descriptive text for an image:
<img src="example.jpg" alt="A happy dog running through a field">
In this example, the alt attribute provides a description of the image that can be read by screen readers and other assistive technologies.
Conclusion
HTML is a fundamental building block of the web, and it's essential for anyone who wants to create web pages and applications. In this tutorial, we've covered the basics of HTML, including tags, attributes, and structure, as well as some advanced topics like HTML5 APIs, responsive design, and accessibility. With this knowledge, you should be well on your way to creating your own web pages and applications.
About the Creator
Bharath S
From Oddanchatram, Tamil Nadu, India



Comments
There are no comments for this story
Be the first to respond and start the conversation.