HTML Tutorial
- Introduction to HTML
- What is HTML
- HTML Text Editors
- HTML Building Blocks
- HTML tags
- HTML Attributes
- HTML Elements
- HTML Formatting
- HTML Heading
- HTML Paragraph
- HTML Phrase Tags
- HTML Anchor
- HTML Image
- HTML Table
- HTML Lists
- HTML Ordered List
- HTML Unordered List
- HTML Description List
- HTML Form
- HTML Form Input
- HTML Form Attribute
- HTML with CSS
HTML Introduction
That sounds like a comprehensive HTML tutorial! It’s great that you’re providing step-by-step guidance for both beginners and professionals. Learning HTML is indeed the foundational step towards building interactive and dynamic websites. If you need any specific tips or resources to enhance your tutorial, feel free to ask!
What is HTML
Those are indeed some fundamental points about HTML:
- HTML stands for HyperText Markup Language: This highlights its purpose as a markup language for creating web pages.
- HTML is used to create web pages and web applications: It’s the backbone of the structure of web content.
- HTML is widely used on the web: Almost every website you encounter on the internet is built using HTML in some form.
We can create a static website by HTML only: HTML alone can create static web pages, which are pages that don’t change content based on user interaction or other factors.
- HTML is a Markup language rather than a programming language: Unlike programming languages such as JavaScript or Python, HTML is primarily concerned with defining the structure and content of web pages rather than executing complex algorithms or logic.
These points provide a good overview of HTML’s role and capabilities.
HTML Code:
Sample HTML Example
Welcome to My Website
About Us
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla faucibus massa at erat consequat, et ultrices purus dictum.
Our Services
- Web Design
- Graphic Design
- Content Writing
This example demonstrates:
Use of <meta> tags for character encoding and viewport settings.
A <link> tag to include an external stylesheet.
Semantic HTML5 elements such as <header>, <nav>, <main>, <section>, and <footer>.
A simple navigation menu using an unordered list (<ul>) with list items (<li>) and anchor tags (<a>).
Content sections with headings (<h2>) and paragraphs (<p>).
Use of an unordered list (<ul>) to list services.
A footer section with copyright information.
A <script> tag to include an external JavaScript file.
This example provides a structure commonly used in modern websites, demonstrating how various HTML elements can be combined to create a complete webpage.
HTML Is
HTML stands for HyperText Markup Language. It’s the standard markup language used to create and design documents on the World Wide Web. HTML defines the structure and layout of a web page by using a variety of tags and attributes to format text, images, multimedia, and other elements.
In simpler terms, HTML is the backbone of any web page. It provides the basic structure and allows web browsers to interpret and display content such as text, images, links, and multimedia. HTML documents are composed of a series of elements, each enclosed in angle brackets, which define the structure and content of the page.
HTML is not a programming language; instead, it’s a markup language used for describing the structure of web pages. However, it often works in conjunction with other technologies like CSS (Cascading Style Sheets) and JavaScript to enhance the presentation and functionality of web pages.
HTML History
The history of HTML is closely intertwined with the development of the World Wide Web. Here’s a brief overview:
1989: HTML’s story begins with Tim Berners-Lee, a British computer scientist working at CERN (European Organization for Nuclear Research). He proposed a system for sharing and accessing information using a hypertext system. This concept laid the foundation for what would become HTML.
1990: Berners-Lee, along with his colleague Robert Cailliau, published a formal proposal for the World Wide Web. This proposal included the first iteration of HTML, which was a simple markup language for creating hypertext documents.
1991: The first version of HTML, HTML 1.0, was released. It included basic tags for formatting text, creating links, and embedding images. This version laid the groundwork for future developments in web technology.
1995: HTML 2.0 was published as an Internet Engineering Task Force (IETF) RFC (Request for Comments). This version introduced new features such as tables, forms, and image maps, expanding the capabilities of HTML.
1997: HTML 3.2 was released as a W3C Recommendation. This version included support for more advanced features like style sheets and improved support for tables and forms.
1999: HTML 4.01 became the standard, offering further enhancements and improvements over previous versions. It introduced features like frames, scripting support, and better accessibility options.
2000: During this decade, the web saw rapid growth and innovation. Technologies like CSS (Cascading Style Sheets) and JavaScript became integral to web development, enabling more sophisticated and dynamic web pages.
2010: HTML5, the latest major version of HTML, was released. HTML5 introduced numerous new features and improvements, including native support for multimedia elements like audio and video, semantic elements for better document structure, and support for offline web applications.
Present: HTML continues to evolve, with ongoing efforts to standardize new features and improve compatibility across different devices and platforms. Web developers continue to use HTML as the foundation for building modern, interactive, and accessible websites and web applications.
Overall, the history of HTML reflects the evolution of the World Wide Web itself, from its humble beginnings as a simple system for sharing information to the complex and dynamic network of interconnected resources that we know today.
HTML Building Blocks
HTML, as the building block of web pages, is composed of various elements that structure and present content. Here are some fundamental building blocks:
Tags: HTML uses tags to define elements within a document. Tags are enclosed in angle brackets, and most come in pairs: an opening tag and a closing tag. For example, <p> is an opening tag for a paragraph, and </p> is its corresponding closing tag.
Attributes: Tags often have attributes that provide additional information about an element. Attributes appear within the opening tag and are used to modify the element’s behavior or appearance. For instance, the <img> tag uses the src attribute to specify the image file’s URL.
Text: Text content within HTML documents is represented by various elements such as headings (<h1> to <h6>), paragraphs (<p>), lists (<ul>, <ol>, <li>), and more. These elements structure and organize textual content.
Links: Hyperlinks are created using the <a> (anchor) tag. They allow users to navigate between different pages on the web or within the same page. The href attribute specifies the URL of the linked page.
Images: Images are displayed using the <img> tag. The src attribute specifies the image file’s URL, and optional attributes like alt provide alternative text for accessibility purposes.
Tables: Tables are created with the <table> tag and its related elements such as <tr> (table row), <th> (table header cell), and <td> (table data cell). Tables are used to display tabular data in rows and columns.
Forms: HTML forms allow users to input data and submit it to a server for processing. Form elements include <form> (form container), <input> (input fields), <textarea> (multiline text input), <select> (dropdown lists), and <button> (buttons).
Semantic elements: HTML5 introduced semantic elements like <header>, <footer>, <nav>, <article>, <section>, and <aside>. These elements provide meaning to the content, making it more understandable for both humans and machines.
Metadata: Metadata elements provide information about the HTML document itself. The <head> section contains elements such as <title> (document title), <meta> (meta-information like character encoding and viewport settings), and <link> (links to external resources like stylesheets).
Comments: Comments in HTML are enclosed within <!– and –> and are not displayed in the browser. They are used to provide notes or explanations within the code for developers’ reference.
These building blocks, along with their attributes and combinations, enable developers to create rich and interactive web experiences using HTML.
Example :
HTML Building Blocks Example
Welcome to My Website
This is a paragraph of text.
- Item 1
- Item 2
- Item 3
Visit Example.com
This example includes:
- Head section with metadata and some internal CSS styles.
- Body section containing various HTML elements:
- Heading (<h1>)
- Paragraph (<p>)
- Unordered list (<ul>) with list items (<li>)
- Anchor link (<a>)
- Image (<img>)
- Form (<form>) with input fields (<input>) and a submit button (<input type=”submit”>)
- Comment (<!– –>) demonstrating how to add comments in HTML.
These are some of the essential building blocks you’ll frequently encounter when creating web pages with HTML.
HTML Tags
HTML tags are the fundamental components of HTML (HyperText Markup Language) documents. They are used to define the structure and content of web pages. Each tag serves a specific purpose and can be customized using attributes. Here’s an explanation of some common HTML tags:
<!DOCTYPE>: This declaration specifies the document type and version of HTML being used. It should appear at the very beginning of an HTML document.
<html>: This tag represents the root element of an HTML document. All other elements are nested within this tag.
<head>: This section contains meta-information about the HTML document, such as the title, character encoding, and links to external resources like stylesheets and scripts.
<title>: This tag specifies the title of the HTML document, which appears in the browser’s title bar or tab.
<body>: This section contains the content of the HTML document that will be displayed in the browser window. It typically includes headings, paragraphs, images, links, forms, and other elements.
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>: These tags represent headings of different levels, with <h1> being the highest level and <h6> the lowest.
<p>: This tag defines a paragraph of text.
<a>: This tag creates hyperlinks, or anchor links, which allow users to navigate between different pages or sections within the same page.
<img>: This tag embeds images into the HTML document. It requires the src attribute to specify the image file’s URL and may include optional attributes like alt for alternative text and width and height for dimensions.
<ul>, <ol>, <li>: These tags are used to create lists. <ul> and <ol> represent unordered and ordered lists, respectively, while <li> represents list items within those lists.
<table>, <tr>, <th>, <td>: These tags are used to create tables. <table> represents the table itself, <tr> represents table rows, <th> represents table header cells, and <td> represents table data cells.
<form>, <input>, <button>, <label>, <textarea>, <select>: These tags are used to create web forms for user input and interaction.
These are just a few examples of HTML tags. There are many more tags available, each serving a specific purpose in structuring and styling web content. Understanding and using HTML tags effectively is essential for building well-structured and visually appealing web pages.
HTML Attributes
HTML attributes provide additional information about HTML elements. They are added to the opening tag of an element and consist of a name and a value, separated by an equals sign (=). Here’s an explanation of HTML attributes:
Syntax: Attributes are added to HTML elements within the opening tag and follow this syntax: attribute=”value”. Multiple attributes can be added to a single element, separated by spaces.
Common Attributes:
id: Specifies a unique identifier for an element within the document. It is often used to target elements with CSS or JavaScript.
class: Specifies one or more class names for an element, allowing it to be styled with CSS or targeted by JavaScript.
src: Specifies the URL of the resource (such as an image or script) to be embedded in the element, often used with <img>, <script>, and <iframe> elements.
href: Specifies the URL of the hyperlink target, used with <a> elements.
alt: Specifies alternative text for an image, displayed if the image cannot be loaded or for accessibility purposes.
title: Specifies a title or tooltip text for an element, displayed when the user hovers over the element.
style: Specifies inline CSS styles for an element, allowing for direct styling.
disabled: Specifies that an input element should be disabled and cannot be interacted with.
checked: Specifies that a checkbox or radio button input element should be pre-selected or pre-checked.
placeholder: Specifies placeholder text for input elements, displayed until the user enters a value.
maxlength: Specifies the maximum number of characters allowed in an input element.
readonly: Specifies that an input element is read-only and cannot be edited by the user.
Boolean Attributes: Some attributes do not require a value and are considered boolean attributes. If present, their presence alone indicates a true value. For example, the disabled attribute: <input type=”text” disabled>. If an attribute is omitted, it is considered false. For example, <input type=”checkbox” checked> will render as a checked checkbox.
Custom Attributes: While using standard attributes is recommended for compatibility and accessibility, HTML5 allows for custom attributes to be added to elements. These attributes should start with data- followed by a descriptive name. They are often used to store custom data for JavaScript functionality or styling.
Understanding and utilizing HTML attributes effectively allows web developers to enhance the functionality, accessibility, and styling of HTML elements within their web pages.
HTML Elements
HTML elements are the basic building blocks of web pages. They define the structure and content of a webpage by encapsulating different types of information, such as text, images, links, and multimedia. Each HTML element consists of a start tag, content, and an end tag, though some elements are self-closing and do not require an end tag. Here’s an overview of HTML elements:
Start Tag: The opening part of an HTML element, enclosed in angle brackets (< and >). It contains the name of the element.
Content: The content of the element, which can include text, other HTML elements, or both.
End Tag: The closing part of an HTML element, also enclosed in angle brackets, preceded by a forward slash (</). It contains the name of the element preceded by the forward slash.
Self-Closing Tags: Some elements do not have content and are self-closing. They consist of a single tag without an end tag.
Here are some common HTML elements:
<html>: The root element of an HTML document, encapsulating all other elements.
<head>: Contains meta-information about the document, such as the title and links to external resources.
<title>: Sets the title of the document, displayed in the browser’s title bar or tab.
<body>: Contains the visible content of the document, such as text, images, links, and multimedia.
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>: Heading elements, used to define headings of different levels, with <h1> being the highest level and <h6> the lowest.
<p>: Paragraph element, used to define paragraphs of text.
<a>: Anchor element, used to create hyperlinks to other web pages or resources.
<img>: Image element, used to embed images into the document.
<ul>, <ol>, <li>: List elements, used to create unordered (bulleted) and ordered (numbered) lists, with <li> representing list items.
<table>, <tr>, <th>, <td>: Table elements, used to create tables with rows (<tr>), header cells (<th>), and data cells (<td>).
<form>: Form element, used to create interactive forms for user input.
<input>, <textarea>, <select>, <button>: Form input elements, used to create various types of input fields, text areas, dropdown lists, and buttons within forms.
Understanding and utilizing HTML elements effectively allows web developers to create well-structured and semantically meaningful web pages.
HTML Formating
HTML provides various formatting elements and attributes to style and structure the content of web pages. These formatting options help make the content visually appealing and easier to read. Here are some common HTML formatting techniques:
Text Formatting:
- Bold Text: Use the <strong> or <b> element to make text bold.
Italic Text: Use the <em> or <i> element to italicize text.
Underlined Text: Use the <u> element to underline text (though it’s not recommended due to accessibility concerns).
- Strikethrough Text: Use the <s> or <strike> element to create a strikethrough effect on text.
Text Alignment:
- Left Alignment: Use CSS text-align: left; or the align attribute with elements like <p> or <div>.
Center Alignment: Use CSS text-align: center; or the align attribute.
Right Alignment: Use CSS text-align: right; or the align attribute.
Text Color:
Use CSS color property to specify the color of text.
Alternatively, you can use the <font> element with the color attribute, but using CSS is the preferred method.
Text Size:
Use CSS font-size property to specify the size of text.
You can also use the <font> element with the size attribute, but CSS is preferred.
Line Breaks and Paragraphs:
Use the <br> element to insert a line break within a paragraph.
Use the <p> element to define paragraphs of text.
Horizontal Rule:
Use the <hr> element to insert a horizontal rule, creating a visible separation between sections.
Preformatted Text:
Use the <pre> element to preserve whitespace and line breaks in text, useful for displaying code snippets or ASCII art.
Comments:
Use the <!– –> syntax to add comments within HTML code. Comments are not displayed in the browser and are used for documentation or notes within the code.
Whitespace:
HTML collapses whitespace by default, so multiple spaces and line breaks are treated as a single space. Use the <br> element for line breaks or CSS for additional spacing.
Remember that while HTML provides basic formatting options, more advanced styling and layout are typically achieved using CSS (Cascading Style Sheets). CSS allows for greater control over the appearance of HTML elements and is the recommended approach for styling web pages.
HTML Heading
HTML headings are used to define the structure and hierarchy of a web page’s content. They are represented by the <h1>, <h2>, <h3>, <h4>, <h5>, and <h6> tags, with <h1> being the most important and <h6> the least. Here’s an example of how they can be used:
HTML Headings Example
This is a Heading Level 1
This is a Heading Level 2
This is a Heading Level 3
This is a Heading Level 4
This is a Heading Level 5
This is a Heading Level 6
Each heading tag represents a different level of importance and is typically styled by browsers with larger font sizes and possibly different font weights to reflect their hierarchical structure. They also assist in accessibility and SEO by providing a clear outline of the content.
HTML Paragraph
HTML paragraphs are used to represent blocks of text. They are represented by the <p> tag. Here’s an example of how you can use paragraphs in HTML:
HTML Paragraph Example
This is a paragraph. It can contain text, images, links, and other HTML elements.
Paragraphs are useful for organizing and presenting textual content on a web page.
Each <p> tag represents a separate paragraph, and browsers typically render paragraphs with some vertical space between them to visually separate the blocks of text. You can include any kind of content within a paragraph, such as text, images, links, lists, etc.
HTML Phrase Tags
In HTML, there isn’t a specific “phrase” tag, but if you’re referring to marking up a phrase within a block of text, you can use the <span> tag.
The <span> tag is a generic inline container used to mark up a piece of text or a part of a document. It doesn’t add any semantic meaning on its own but can be styled or manipulated with CSS or JavaScript.
Here’s an example of how you can use the <span> tag to highlight a phrase within a paragraph:
HTML Span Tag Example
This is a highlighted phrase within a paragraph.
In this example, the phrase “highlighted phrase” is wrapped in a <span> tag with a class of “highlight”. CSS is then used to apply custom styling to this span, making the text red and bold
HTML Anchor
In HTML, the anchor tag <a> is used to create hyperlinks. Hyperlinks are clickable links that allow users to navigate between web pages or to specific parts of the same page. Here’s how you can use the anchor tag:
HTML Anchor Example
Visit Example website.
In this example:
<a>: This is the anchor tag.
href=”https://www.example.com”: This is the attribute that specifies the URL of the page the link goes to. It’s important to include the full URL, including the protocol (e.g., https://).
Example: This is the text that will be displayed as the link. Users can click on this text to navigate to the specified URL.
You can also use the anchor tag to create internal links within the same page by providing an id attribute to the target element and using it as the value of the href attribute in the anchor tag. For example:
HTML Anchor Example
Section 2
This is the content of section 2.
In this example, clicking on the “Jump to Section 2” link will scroll the page to the <h2> element with the id attribute set to “section2”.
HTML Image
In HTML, you can use the <img> tag to insert images into a web page. Here’s how you can use it:
HTML Image Example
In this example:
<img>: This is the image tag.
src=”image.jpg”: This is the attribute that specifies the URL or path of the image file. You need to replace “image.jpg” with the actual path to your image file.
alt=”Description of the image”: This is the attribute that provides alternative text for the image. It is important for accessibility and SEO. Replace “Description of the image” with a brief description of the image.
You can also specify additional attributes such as width and height to control the size of the image, or use CSS to style the image further. Here’s an example with additional attributes:
HTML Image Example
In this example, the image will be displayed at a width of 300 pixels and the height will be adjusted automatically to maintain the aspect ratio.
HTML Table
HTML tables are used to display data in rows and columns. Here’s a basic example of how to create a simple table:
HTML Table Example
Simple Table
Name
Age
City
John
30
New York
Jane
25
Los Angeles
Bob
35
Chicago
This is a simple table displaying people’s names, ages, and cities.
Simple Table
Name | Age | City |
---|---|---|
John | 30 | New York |
Jane | 25 | Los Angeles |
Bob | 35 | Chicago |
In this example:
- <table>: This tag defines the start of the table.
- <tr>: This tag defines a row in the table.
- <th>: This tag defines a header cell in the table.
- <td>: This tag defines a standard cell in the table.
- border-collapse: collapse;: This CSS property ensures that adjacent cells share borders.
- padding: 8px;: This CSS property adds space between the cell content and the cell border.
- background-color: #f2f2f2;: This CSS property sets the background color of header cells.
You can add more rows and columns as needed, and you can further style the table using CSS to achieve the desired appearance.
HTML Lists
HTML offers different types of lists to structure and present information. The three main types are unordered lists (<ul>), ordered lists (<ol>), and definition lists (<dl>). Here’s an example of each:
Unordered List Example
Shopping List
- Apples
- Bananas
- Oranges
Ordered List Example
Steps to Make Pancakes
- Whisk flour, sugar, baking powder, and salt in a bowl.
- Combine eggs, milk, and melted butter in another bowl.
- Pour wet ingredients into dry ingredients and stir until just combined.
- Heat a skillet over medium heat and pour batter onto the skillet.
- Cook until bubbles form on the surface, then flip and cook until golden brown.
Definition List Example
Web Development Glossary
- HTML
- HyperText Markup Language - the standard markup language for creating web pages.
- CSS
- Cascading Style Sheets - a stylesheet language used for describing the presentation of a document written in HTML.
- JavaScript
- A programming language that enables interactive web pages and is essential for web development.
In each example:
- <ul>, <ol>, <dl>: These tags define the start of an unordered list, ordered list, and definition list respectively.
- <li>: This tag defines each list item.
- <dt>: This tag defines the term in a definition list.
- <dd>: This tag defines the description of the term in a definition list.
Lists are versatile and can be styled with CSS to match the design of your webpage.
HTML Ordered List
an HTML ordered list (<ol>) is used to create a list where each item is numbered. Here’s an example of how you can create an ordered list
HTML Ordered List Example
Steps to Bake a Cake
- Preheat the oven to 350°F (180°C).
- Grease and flour a cake pan.
- Combine flour, sugar, baking powder, and salt in a bowl.
- In another bowl, beat eggs, milk, and vanilla extract together.
- Pour the wet ingredients into the dry ingredients and mix until smooth.
- Pour the batter into the cake pan and smooth the top.
- Bake in the preheated oven for 30-35 minutes or until a toothpick inserted into the center comes out clean.
- Remove from the oven and let it cool in the pan for 10 minutes.
- Transfer the cake to a wire rack to cool completely before frosting.
- Once cooled, frost the cake as desired.
- Slice and serve!
In this example:
<ol>: This tag defines the start of an ordered list.
<li>: This tag defines each list item.
Each list item (<li>) contains a step in the process of baking a cake.
The numbers for each item in the list will be automatically generated by the browser.
You can customize the appearance of the ordered list using CSS to change things like the numbering style, alignment, font, etc.
HTML Unordered List
An HTML unordered list (<ul>) is used to create a list where each item is bulleted or marked with a similar symbol. Here’s an example of how you can create an unordered list:
HTML Unordered List Example
Benefits of Regular Exercise
- Improves cardiovascular health
- Helps maintain a healthy weight
- Strengthens muscles and bones
- Boosts mood and reduces stress
- Enhances flexibility and mobility
- Improves sleep quality
In this example:
<ul>: This tag defines the start of an unordered list.
<li>: This tag defines each list item.
Each list item (<li>) contains a benefit of regular exercise.
The bullets for each item in the list will be automatically generated by the browser.
You can customize the appearance of the unordered list using CSS to change things like the bullet style, alignment, font, etc.
HTML Description List
An HTML description list (<dl>) is used to define terms and their corresponding descriptions. Each term is represented using the <dt> tag, and each description is represented using the <dd> tag. Here’s an example of how you can create a description list:
HTML Description List Example
Web Development Glossary
- HTML
- HyperText Markup Language - the standard markup language for creating web pages.
- CSS
- Cascading Style Sheets - a stylesheet language used for describing the presentation of a document written in HTML.
- JavaScript
- A programming language that enables interactive web pages and is essential for web development.
In this example:
<dl>: This tag defines the start of a description list.
<dt>: This tag defines a term in the description list.
<dd>: This tag defines the description of the corresponding term.
Each <dt> tag represents a term in the glossary, and each <dd> tag provides the description of that term.
You can style the appearance of the description list using CSS to match the design of your webpag
HTML Form
An HTML form is a section of a document which contains controls such as text fields, password fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for processing such as name, email address, password, phone number, etc. .
HTML Form Example
Contact Us
In this example:
<form>: This tag defines the start of a form.
action=”/submit_form.php”: This attribute specifies the URL to which the form data will be submitted.
method=”post”: This attribute specifies the HTTP method used to submit the form data (in this case, POST).
<label>: This tag defines a label for an input element.
<input>: This tag defines an input field (text, email, etc.).
type=”text”, type=”email”: These attributes specify the type of input field (text, email, etc.).
id, name: These attributes provide identifiers for the input fields.
required: This attribute specifies that the input field must be filled out before submitting the form.
<textarea>: This tag defines a multiline text input field.
<input type=”submit”>: This tag defines a submit button for the form.
When the form is submitted, the data will be sent to the specified action URL using the specified method (POST in this case). You would typically replace “/submit_form.php” with the URL of the script that processes the form data on the server side.
HTML Form Input
Below is a simple example of an HTML form with various input types:
HTML Form Inputs Example
User Registration Form
In this form:
text: This is for general text input, like usernames.
password: This hides the input, commonly used for passwords.
email: This ensures that the input follows email format.
number: This restricts input to numerical values.
date: This provides a date picker for input.
radio: This allows the user to choose only one option from a set.
checkbox: This allows the user to choose multiple options from a set.
select: This provides a dropdown menu for selection.
Each input type can have additional attributes like required, which ensures that the field must be filled before submitting the form.
HTML form Attribute
The form attribute in HTML is used to associate a form control with a specific form. When you’re working with multiple forms on a webpage, you can use the form attribute to specify which form an input element belongs to. This attribute takes the ID of the form as its value.