Skip to content

billahdotdev/Learn-HTML

Repository files navigation

What is HTML?

HTML (HyperText Markup Language) is a coding language used to create web pages. It tells web browsers how to structure and display content like text, images, and links. It's essential for building websites.

Why should I learn HTML?

HTML is like the ABCs of web development. It's the basic language you need to create web pages. Without it, you can't even start building a website. So, if you're serious about becoming a web developer, learning HTML is a must.

What does HTML code look like?

                  <!DOCTYPE html>
                  <html lang="en">
                  <head>
                      <meta charset="UTF-8">
                      <meta name="viewport" content="width=device-width, initial-scale=1.0">  
                      <title>My First Web Page</title>
                  </head>
                  <body>
                      <h1>Hello, World!</h1>
                      <p>This is a paragraph.</p>
                      <img src="image.jpg" alt="An image">
                      <a href="https://www.example.com">Click here</a> to visit Example.com.
                  </body>
                  </html>

Familiarize yourself with HTML (no worry! even if you do not understand them now!)

1. HTML (HyperText Markup Language): The standard language for creating web pages and applications.

2. Tag: A markup construct in HTML used to define elements within a document, enclosed by angle brackets, such as <p> for paragraphs.

3. Element: The combination of an opening tag, content, and a closing tag, defining a specific part of a webpage, such as paragraphs (<p>), headings (<h1> to <h6>), and images (<img>).

4. Attribute: Additional information is provided within the opening tag of an element to modify its behavior or provide metadata, such as src for image source or href for hyperlink reference.

5. Document: A web page created using HTML, typically combining elements structured within a hierarchical format.

6. Head: The portion of an HTML document that contains metadata and links to external resources, including the element.

7. Body: The portion of an HTML document that contains the content visible to users, including text, images, and other media, enclosed within the element.

8. Heading: An HTML element used to define headings or titles within a document, ranging from <h1> (the highest level) to <h6> (the lowest level).

9. Paragraph: An HTML element used to define paragraphs of text within a document, enclosed by <p> tags.

10. Link: An HTML element used to create hyperlinks to other web pages or resources, defined by the <a> (anchor) tag, with the href attribute specifying the destination URL.

11. Image: An HTML element used to embed images within a document, defined by the <img> tag, with the src attribute specifying the image source.

12. List: An HTML element used to create lists, including ordered lists (<ol>), unordered lists (<ul>), and list items (<li>).

13. Table: An HTML element used to organize data into rows and columns, defined by the tag, with rows (<tr>), cells (<td>), and header cells (<th>).

14. Form: An HTML element used to create interactive forms for user input, defined by the tag, with input fields (<input>) and other form elements.

15. Semantic HTML: HTML elements that provide meaning and structure to the content, such as <header>, <footer>, <nav>, <article>, <section>, and <aside>.

16. Div: A generic container element used to group and style content, often used for layout purposes, defined by the <div> tag.

17. Span: A generic inline container element used to apply styles or mark up a specific text portion within a larger block of content, defined by the <span> tag.

18. Inline vs. Block Elements: Inline elements, like <span> and <a>, do not start on a new line and only take up as much width as necessary, while block elements, like <div> and <p>, start on a new line and take up the full width available.

19. Attribute Value: The value assigned to an attribute within an HTML tag, such as "blue" in <div style="color: blue;">.

20. Comment: An HTML comment is a text within an HTML document not displayed in the browser but can be used to provide notes or explanations to developers, defined by the <!-- --> syntax.

21. DOCTYPE: The document type declaration (<!DOCTYPE html>) specifies the version of HTML used in a document and helps browsers render web pages correctly.

22. Metadata: Information about the HTML document that is not displayed on the page itself, such as the document's character encoding (<meta charset="utf-8">) or viewport settings (<meta name="viewport" content="width=device-width, initial-scale=1.0">).

23. Anchor: Another term for a hyperlink, created using the <a> tag.

24. Empty Element: An HTML element that does not require closing tags, such as <img>, <br>, and <input>, as they do not contain any content between opening and closing tags.

25. HTML Entity: Special codes represent reserved characters in HTML, such as &lt; for < and &amp; for &.

26. Inline Style: CSS styles applied directly to an HTML element using the style attribute, such as <div style="color: red;">.

27. Block vs. Inline Elements: Block-level elements start on a new line and take up the full width available, while inline elements only take up as much width as necessary and do not start on a new line.

28. Nesting: Placing one HTML element inside another, creates a hierarchical structure, such as placing a <p> element inside a <div> element.

29. Semantic Markup: Using HTML elements that convey the meaning of the content, improving accessibility and search engine optimization.

30. Validation: Checking HTML code for errors and ensuring it conforms to the standards set by the W3C (World Wide Web Consortium).

31. Whitespace: The space, tab, or newline characters used for formatting and readability within HTML documents. While web browsers typically ignore whitespace, it can impact the layout and readability of your HTML code.

32. Escape Characters: Special characters in HTML with predefined meanings, such as < and > for tags. To display these characters as text rather than interpreting them as HTML, you can use escape characters like &lt; and &gt;.

33. Semantic Structure: Organizing content using semantic HTML elements such as <header>, <footer>, <nav>, <main>, and <article>, which provide meaning and context to different sections of a webpage.

34. HTML5: The latest version of HTML, which introduced new elements, attributes, and APIs to enhance web development, including <video>, <audio>, <canvas>, and <svg> elements.

35. Responsive Design: Designing web pages that adapt and respond to different screen sizes and devices, achieved using techniques like media queries and flexible layouts in HTML and CSS.

36. Accessibility: Ensuring that web content is accessible to users with disabilities, achieved by using semantic HTML, providing alternative text for images (alt attribute), and following accessibility guidelines such as the Web Content Accessibility Guidelines (WCAG).

37. SEO (Search Engine Optimization): Optimizing web pages to improve their visibility and ranking in search engine results, achieved by using relevant keywords, descriptive titles, and semantic HTML markup.

38. Deprecated Elements: HTML elements that are no longer recommended for use in modern web development due to being outdated or replaced by newer standards, such as <font>, <center>, and <strike>.

39. Cross-browser Compatibility: Ensuring that web pages look and function consistently across different web browsers, achieved by testing and optimizing HTML, CSS, and JavaScript code for compatibility with popular browsers like Chrome, Firefox, Safari, and Edge.

40. Whitespace Collapsing: In HTML, consecutive spaces, tabs, and newline characters are collapsed into a single space when rendered by the browser, except within elements styled with CSS to preserve whitespace.

41. Escape Sequences: Special sequences of characters used to represent reserved characters or non-printable characters within HTML, such as   for a non-breaking space or " for a double quote.

42. inline Frames (iframes): An HTML element (<iframe>) used to embed another HTML document within the current document. This is commonly used for embedding videos, maps, or other external content.

43. Meta Tags: HTML tags provide metadata about the HTML document, such as character encoding (<meta charset="utf-8">), viewport settings (<meta name="viewport" content="width=device-width, initial-scale=1.0">), or specifying keywords and description for search engines.

44. Blockquote: An HTML element (<blockquote>) indicates that a section of text is quoted from another source. It is commonly styled to stand out from the rest of the content.

45. Abbreviation and Acronym: HTML elements (<abbr> and <acronym>) used to mark up abbreviations and acronyms in text. They can include a title attribute to provide the full expansion of the abbreviation or acronym.

46. Semantic Elements for Time: HTML5 introduced elements like <time> for marking up dates, times, or durations in a machine-readable format, enhancing accessibility and search engine understanding.

47. Web Standards: Guidelines and specifications set by organizations like the W3C to ensure interoperability and compatibility among web technologies. Adhering to web standards promotes consistency and accessibility in web development.

Important Elements:

  1. <!DOCTYPE html>: Tells the browser the document type (HTML5).

  2. <html>: The root element of an HTML page.

  3. <head>: Contains metadata (data about data) like the title, character encoding, and links to stylesheets or scripts.

  4. <body>: Contains the content of the webpage (headings, paragraphs, images, etc.).

HTML Tags and Elements

An HTML element consists of a start tag, content, and an end tag. Here's an example of a simple element:

<p>This is a paragraph.</p>

In this case:

<p> is the start tag.

</p> is the end tag.

• This is a paragraph. is the content.

Self-Closing Tags

Some HTML elements don’t require a closing tag. These are called self-closing tags or void elements. For example:

<img src="image.jpg" alt="A sample image">

The tag is self-closing because it doesn't contain any content, just attributes.

Let's Examine an HTML Code: Just try to read all Comments <!---XYZ--->

            <!DOCTYPE html> <!-- Declares the document type -->
            <html lang="en"> <!-- Specifies the language of the document -->
            
            <head>
                <meta charset="UTF-8"> <!-- Sets the character encoding to UTF-8 -->
                <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Sets the viewport for responsive design -->
                <title>My Web Page</title> <!-- Sets the title of the web page -->
                
                <!-- Linking to an external CSS file -->
                <link rel="stylesheet" href="styles.css">
                
                <!-- Embedding CSS styles directly within the HTML document -->
                <style>
                    body {
                        font-family: Arial, sans-serif; /* Setting the font family for the entire document */
                        background-color: #f0f0f0; /* Setting the background color */
                    }
                    h1 {
                        color: blue; /* Changing the color of the h1 headings */
                    }
                </style>
                
                <!-- Including JavaScript -->
                <script src="script.js"></script>
                
                <!-- Inline JavaScript -->
                <script>
                    function greet() {
                        alert('Hello, world!'); /* Function to greet users with an alert */
                    }
                </script>
            </head>
            
            <body>
                <!-- Header Section -->
                <header>
                    <h1>Welcome to My Website</h1> <!-- Heading for the website title -->
                    <nav>
                        <!-- Navigation Links -->
                        <ul>
                            <li><a href="#home">Home</a></li> <!-- Link to the home section -->
                            <li><a href="#about">About</a></li> <!-- Link to the about section -->
                            <li><a href="#contact">Contact</a></li> <!-- Link to the contact section -->
                        </ul>
                    </nav>
                </header>
                
                <!-- Main Content Section -->
                <main>
                    <!-- Article Section -->
                    <article>
                        <h2>About Us</h2> <!-- Heading for the about section -->
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae fermentum nunc. Integer vitae orci vel odio vestibulum tempus.</p> <!-- Placeholder text for the about content -->
                    </article>
                    
                    <!-- Sidebar Section -->
                    <aside>
                        <h2>Latest News</h2> <!-- Heading for the latest news section -->
                        <p>Stay tuned for updates!</p> <!-- Placeholder text for the latest news content -->
                    </aside>
                </main>
                
                <!-- Footer Section -->
                <footer>
                    <p>&copy; 2024 My Website. All rights reserved.</p> <!-- Copyright information -->
                </footer>
            
                <!-- Embedding an image -->
                <img src="image.jpg" alt="A beautiful image"> <!-- Embedding an image with alt text -->
            
                <!-- Creating a form -->
                <form action="/submit" method="post">
                    <label for="name">Name:</label> <!-- Label for the name input field -->
                    <input type="text" id="name" name="name" required> <!-- Text input for name with required attribute -->
                    <label for="email">Email:</label> <!-- Label for the email input field -->
                    <input type="email" id="email" name="email" required> <!-- Email input with required attribute -->
                    <button type="submit">Submit</button> <!-- Submit button -->
                </form>
            
                <!-- Including an iframe for embedding external content -->
                <iframe src="https://www.example.com" title="External Content" width="400" height="300"></iframe> <!-- Embedding an external content -->
            
                <!-- Adding a table -->
                <table>
                    <caption>Monthly Sales Report</caption> <!-- Caption for the table -->
                    <thead>
                        <tr>
                            <th>Date</th> <!-- Table header for date -->
                            <th>Product</th> <!-- Table header for product -->
                            <th>Quantity</th> <!-- Table header for quantity -->
                            <th>Revenue</th> <!-- Table header for revenue -->
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>2024-01-01</td> <!-- Table data for date -->
                            <td>Product A</td> <!-- Table data for product -->
                            <td>100</td> <!-- Table data for quantity -->
                            <td>$1000</td> <!-- Table data for revenue -->
                        </tr>
                        <!-- Additional rows here -->
                    </tbody>
                </table>
            
                <!-- Adding semantic HTML5 elements for better structure -->
                <section>
                    <h2>Featured Products</h2> <!-- Heading for featured products section -->
                    <!-- Product listings here -->
                </section>
                
                <!-- Using HTML5 audio and video elements for multimedia content -->
                <audio controls>
                    <source src="music.mp3" type="audio/mpeg"> <!-- Audio source with controls -->
                    Your browser does not support the audio element.
                </audio>
            
                <video controls>
                    <source src="video.mp4" type="video/mp4"> <!-- Video source with controls -->
                    Your browser does not support the video element.
                </video>
            
                <!-- Adding SVG graphics -->
                <svg width="100" height="100">
                    <circle cx="50" cy="50" r="40" fill="red" /> <!-- Circle SVG element -->
                </svg>
            
                <!-- Adding a canvas for dynamic graphics -->
                <canvas id="myCanvas" width="200" height="100"></canvas> <!-- Canvas for dynamic graphics -->
            
                <!-- Adding a progress bar -->
                <progress value="70" max="100"></progress> <!-- Progress bar -->
            
                <!-- Adding a meter element -->
                <meter value="0.7"></meter> <!-- Meter element -->
            
                <!-- Adding a details and summary for collapsible content -->
                <details>
                    <summary>Click to reveal more</summary> <!-- Summary for collapsible content -->
                    <p>This is more information that can be revealed.</p> <!-- Content to be revealed -->
                </details>
            
                <!-- Adding a time element for date and time -->
                <p>Document last updated: <time datetime="2024-04-08T09:00">April 8, 2024</time></p> <!-- Time element for date and time -->
            
                <!-- Adding a datalist for pre-defined options in input -->
                <label for="browser">Choose your browser:</label> <!-- Label for datalist -->
                <input list="browsers" id="browser" name="browser"> <!-- Input field with datalist -->
                <datalist id="browsers">
                    <option value="Chrome"> <!-- Pre-defined option for Chrome -->
                    <option value="Firefox"> <!-- Pre-defined option for Firefox -->
                    <option value="Edge"> <!-- Pre-defined option for Edge -->
                    <option value="Safari"> <!-- Pre-defined option for Safari -->
                </datalist>
            
                <!-- Adding a summary for table headers -->
                <table>
                    <caption>Monthly Sales Report</caption> <!-- Caption for the table -->
                    <thead>
                        <tr>
                            <th><abbr title="Date">Date</abbr></th> <!-- Table header abbreviation for date -->
                            <th><abbr title="Product">Product</abbr></th> <!-- Table header abbreviation for product -->
                            <th><abbr title="Quantity">Qty</abbr></th> <!-- Table header abbreviation for quantity -->
                            <th><abbr title="Revenue">Rev</abbr></th> <!-- Table header abbreviation for revenue -->
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>2024-01-01</td> <!-- Table data for date -->
                            <td>Product A</td> <!-- Table data for product -->
                            <td>100</td> <!-- Table data for quantity -->
                            <td>$1000</td> <!-- Table data for revenue -->
                        </tr>
                        <!-- Additional rows here -->
                    </tbody>
                </table>
            
                <!-- Adding a summary for figure elements -->
                <figure>
                    <img src="image.jpg" alt="A beautiful image"> <!-- Image within a figure element -->
                    <figcaption>A caption for the image.</figcaption> <!-- Caption for the image -->
                </figure>
            
                <!-- Adding a keygen for generating cryptographic keys -->
                <label for="key">Generate a key:</label> <!-- Label for keygen -->
                <keygen id="key" name="key" challenge="random challenge string"> <!-- Keygen for generating cryptographic keys -->
            
                <!-- Adding a mark element for highlighting text -->
                <p>This is <mark>highlighted</mark> text.</p> <!-- Mark element for highlighting text -->
            
                <!-- Adding a dialog for interactive prompts -->
                <dialog open> <!-- Dialog box -->
                    <p>This is a dialog box.</p> <!-- Content within the dialog box -->
                    <button>Close</button> <!-- Close button for the dialog box -->
                </dialog>
            
                <!-- Adding a nav element for navigation links -->
                <nav>
                    <ul>
                        <li><a href="#home">Home</a></li> <!-- Link to the home section -->
                        <li><a href="#about">About</a></li> <!-- Link to the about section -->
                        <li><a href="#contact">Contact</a></li> <!-- Link to the contact section -->
                    </ul>
                </nav>
            
            </body>
            
            </html>

ADVANCED & DEEPER HTML TOPICS

1. Custom Data Attributes (data-*)

Used to store extra information on elements without using extra classes or IDs.

<div data-user-id="12345" data-role="admin">John Doe</div>

Useful in JavaScript to store and retrieve data without polluting classes or IDs.

2. HTML Global Attributes

Attributes you can use on any HTML element:

id

class

style

title (tooltip text)

hidden

tabindex

draggable

contenteditable

lang

<p id="info" class="highlight" title="Tooltip here">Hover me</p>

3. Contenteditable

Makes any element editable directly in the browser.

<div contenteditable="true">You can edit this text!</div>

Great for building simple editors or admin tools.

4. Hidden Attribute

Hides the element from the page (but still in the DOM).

<p hidden>This won't be visible.</p>

Can be toggled using JavaScript.

5. HTML Entity Reference Table

&lt;   = <

&gt;   = >

&amp;  = &

&nbsp; = (non-breaking space)

&copy; = ©

&reg;  = ®

&trade; = ™

&hellip; = …

&mdash; = —

Essential when displaying code, symbols, or typographic content.

6. Fieldset and Legend

Group form fields and label them semantically.

<fieldset>
  <legend>Contact Info</legend>
  <label>Name: <input type="text"></label>
  <label>Email: <input type="email"></label>
</fieldset>

Improves accessibility and grouping.

7. Label for Attribute Best Practice

Connects labels to input fields for better UX and accessibility.

<label for="email">Email:</label>
<input type="email" id="email">

Clicking the label focuses the input.

8. Autofocus, Autocomplete, and Placeholder

Enhance user experience:

<input type="text" placeholder="Enter your name" autocomplete="on" autofocus>

placeholder: hint text

autocomplete: auto-fill from browser

autofocus: focus on page load

9. HTML Validation Attributes

Client-side input checking:

required

min, max, maxlength

pattern

  <input type="text" required pattern="[A-Za-z]{3,}">

HTML forms can validate input without JavaScript.

10. Accessible Forms Using + ARIA

Introduce aria-label, aria-hidden, role, etc.

<input type="text" aria-label="Search term">

Good for SEO and accessibility.

11. Noscript Tag

Provides fallback content for users with JavaScript disabled.

<noscript>
  <p>Please enable JavaScript to use this website properly.</p>
</noscript>

Useful when your site relies heavily on JavaScript functionality.

12. Element

Holds HTML that isn’t rendered immediately but can be cloned via JavaScript.

<template id="card-template">
  <div class="card">
    <h2></h2>
    <p></p>
  </div>
</template>

Great for dynamic UIs.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages