Technology/Software Development/Web development/HTML

From WikiKnowledgeBase

HTML Basics

HTML (Hypertext Markup Language) is a fundamental language used for creating and structuring the content of web pages. It provides a way to define the elements and their relationships on a web page, allowing browsers to interpret and display the content appropriately. This article provides a beginner's introduction to HTML, covering its basic syntax and commonly used elements.

HTML Structure[edit]

HTML documents are structured using a set of tags that define the different elements on a web page. An HTML document typically consists of two main sections: the head and the body.

The head section contains meta-information about the document, such as the title, character encoding, and links to external stylesheets or scripts. It doesn't directly affect the visible content on the page.

The body section contains the actual content that will be displayed in the browser window. It includes text, images, links, and other elements that make up the web page.

HTML Tags and Elements[edit]

HTML elements are defined using tags, which are enclosed in angle brackets (< and >). Tags are usually paired, with an opening tag and a closing tag. The opening tag starts with the tag name, followed by any attributes, and the closing tag is the same as the opening tag but with a forward slash (/) before the tag name.

For example, the <h1> tag is used to define a heading. An example of a heading would be: <h1>This is a Heading</h1>

Some commonly used HTML elements include:

  • <p>: Used to define a paragraph of text.
  • <a>: Used to create a hyperlink.
  • <img>: Used to display an image on the web page.
  • <ul> and <li>: Used to create unordered lists.
  • <ol> and <li>: Used to create ordered lists.
  • <div>: Used to create a container to group other elements.
  • <span>: Used to apply styles or manipulate specific parts of the text.

Attributes[edit]

HTML elements can have attributes, which provide additional information about the element. Attributes are placed within the opening tag and consist of a name-value pair. The value is typically enclosed in quotation marks.

For example, the <a> tag uses the href attribute to define the URL to which the hyperlink points: <a href="https://www.example.com">Visit Example</a>

Attributes can also be used to specify styles, define alternative text for images, or provide additional information for accessibility purposes.

HTML Comments[edit]

HTML comments are used to add explanatory notes or to temporarily disable a section of code. Comments are not displayed on the web page and are only visible in the HTML source code.

Comments are written using the <!-- --> syntax. Anything between the opening '<!--' and closing '-->' is considered a comment.

For example: <!-- This is a comment. -->

Conclusion[edit]

HTML is the backbone of the web and forms the foundation for creating web pages. By understanding the basic syntax and commonly used elements, beginners can start building simple web pages and gradually expand their knowledge to create more complex and interactive websites. HTML provides a solid starting point for anyone interested in web development, and with practice, it becomes an essential tool in a developer's toolkit.

For a deeper dive into HTML, we recommend looking at the Mozilla docs here - https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML


Next article - CSS