Writing HTML (Hypertext Markup Language) involves creating a set of instructions that web browsers use to structure content on the web. Here's a basic guide to writing HTML code:
Create a New HTML Document:
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Your Page Title</title> </head> <body> <!-- Your content goes here --> </body> </html>
<!DOCTYPE html>
declares the document type and version of HTML.<html>
is the root element of the HTML document.<head>
contains meta-information about the HTML document, such as character set and viewport settings.<body>
contains the content of the HTML document.
Adding Headings:
html<h1>This is a Heading 1</h1> <h2>This is a Heading 2</h2> <!-- ... --> <h6>This is a Heading 6</h6>
Paragraphs:
html<p>This is a paragraph of text.</p>
Lists:
- Unordered List:html
<ul> <li>Item 1</li> <li>Item 2</li> <!-- ... --> </ul>
- Ordered List:html
<ol> <li>Item 1</li> <li>Item 2</li> <!-- ... --> </ol>
- Unordered List:
Links:
html<a href="https://www.example.com">Visit Example.com</a>
Images:
html<img src="image.jpg" alt="Description of the image">
Forms:
html<form action="/submit" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username"> <br> <label for="password">Password:</label> <input type="password" id="password" name="password"> <br> <input type="submit" value="Submit"> </form>
Tables:
html<table border="1"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <!-- ... --> </table>
Divs (Division):
html<div> <!-- Content goes here --> </div>
Remember that HTML provides the structure for your web content, and you can use CSS (Cascading Style Sheets) for styling and JavaScript for interactivity. Always close HTML tags properly and adhere to web standards for better compatibility across different browsers.