by Ritwick Dey
e.g. button, link, textbox, form, headings, div
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First HTML Page</title>
</head>
<body>
</body>
</html>Everything inside tags <> is an HTML element
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>
<body>
<h1>A heading</h1>
<a href="https://www.google.com/">Link text</a>
</body>
</html>Image source: https://en.wikipedia.org/wiki/File:DOM-model.svg
Text
Adding internal JavaScript to your webpage
<!DOCTYPE html>
<html>
<head>
<title>You Are Here</title>
</head>
<body>
<p>Press <code>alt+command+i</code> Mac / <code>ctrl+shift+i</code> Windows to open your Dev Tools. Make sure the console tab is open.</p>
<script>
(function() {
// This is where you would put your Javascript
// Inside the script tags
console.log("Success!");
})();
</script>
</body>
</html>Adding an external CSS file to your webpage
(optimal way)
<!DOCTYPE html>
<html>
<head>
<title>You Are Here</title>
<script src="path/to/file.js" defer></script>
</head>
<body>
<p>Press <code>alt+command+i</code> Mac /
<code>ctrl+shift+i</code> Windows to open your Dev Tools.
Make sure the console tab is open.</p>
</body>
</html>.message {
color: blue;
}CSS file
HTML file
|
<!DOCTYPE html> |
declaration defines the document type and version of HTML used in the document. |
|
<html> |
element is the root element of the HTML document and contains all other elements. |
| <head> | element contains metadata about the document, such as the title, which is displayed in the browser's title bar or tab. |
|
<meta charset="UTF-8"> |
declaration specifies the character encoding for the document, which is set to UTF-8 |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | declaration is used to control the scaling of the page on smaller screens, such as those of mobile devices |
| <title> | element specifies the title of the document, which is displayed in the browser's title bar or tab |
| <body> | element contains the content of the HTML document, such as text, images, and other elements. |
| <h1> - <h6> | Defines headings of different sizes | <h1>My Name</h1> |
| <p> | Defines a paragraph | <p>I am a software engineer</p> |
|
<img> |
Displays an image | <img src="profile.jpg" alt="My Profile Picture"> |
| <ul> | Defines an unordered list | <ul>...</ul> |
| <li> | Defines a list item | <li>Graduated from XYZ University</li> |
| <a> | Defines a hyperlink | <a href="https://www.linkedin.com/in/myusername">My LinkedIn Profile</a> |
Anatomy of an HTML Head
<meta charset="UTF-8">attribute
attribute name
character encoding value
element
<meta name="viewport" content="width=device-width, initial-scale=1.0">attribute value
attribute
value
Anatomy of an HTML Head cont...
Anatomy of an HTML button element
<button type="submit">Text Content</button>attribute
attribute name
attribute value
element
| <header> | Used to define a header for a document or section |
|---|---|
| <nav> | Used to define navigation links |
| <main> | Used to define the main content of a document |
| <article> | Used to define an independent self-contained piece of content |
| <section> | Used to define a section of a document |
| <footer> | Used to define a footer for a document or section |
| <figure> | Used to define self-contained content, such as images, diagrams, code snippets, etc. |
| <figcaption> | Used to provide a caption for a <figure> element |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sample Semantic HTML Page</title>
</head>
<body>
<header>
<h1>Welcome to our site</h1>
<nav>
<ul>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="about">
<h2>About Us</h2>
<p>Learn about our company and what we offer.</p>
</section>
<section id="services">
<h2>Our Services</h2>
<ul>
<li>Service 1</li>
<li>Service 2</li>
<li>Service 3</li>
</ul>
</section>
<section id="contact">
<h2>Contact Us</h2>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" value="Submit">
</form>
</section>
</main>
<footer>
<p>Copyright © 2023 Sample Site</p>
</footer>
</body>
</html>
Anatomy of an HTML link element
An HTML link is a special tag that allows you to link one web page to another.
<a href="URL">Link Text</a>attribute
attribute name
attribute value
element
Anatomy of an HTML internal link
<a href="#section1">Link to Section 1</a><a> tag is used to create a hyperlink in HTMLhref attribute specifies the destination of the link, in this case #section1 which means it is an internal link to a specific section within the same HTML document<a> tags is the text that will be displayed as the link on the webpageAnatomy of an HTML external link
<a href="https://www.example.com">Link</a>Anatomy of an HTML email link
<a href="mailto:example@email.com">Send email</a>The display text: This is the text that is displayed as a hyperlink on the webpage. The display text is placed between the opening and closing "a" tags. For example, <a href="mail to:example@email.com">Send an email</a>The closing "a" tag: </a>
When a user clicks on the email link, their default email client will open with a new email pre-filled with the specified email address.
Understanding the Fundamentals of HTML Forms
<form>
<label for="input-field">Input Field:</label>
<input type="text" id="input-field" name="input-field">
<label for="radio-button">Radio Button:</label>
<input type="radio" id="radio-button" name="radio-group">
<label for="checkbox">Checkbox:</label>
<input type="checkbox" id="checkbox" name="checkbox">
<button type="submit" value="Submit">
</form>Labels: Labels are used to describe the input elements and are associated with a specific input element using the "for" attribute.
<form id="randomForm">
<!-- ... -->
</form>
HTML
submit
<input type="text" id="name">HTML
By using the event target's value
change or input
<select id="department" class="form-control">
<option value=""></option>
<option value="web-design">Web Design</option>
<option value="web-development">Web Development</option>
<!-- ... -->
</select>
HTML
change
<input type="checkbox" id="addExtraCheese">
<label or="addExtraCheese">Extra Cheese</label>
HTML
click or change
<input type="text" required/>HTML
input validation
The required attribute in HTML marks an input field as mandatory. The form cannot be submitted until a value is entered in the required field.