Home > Web Front-end > JS Tutorial > body text

Develop yourself to build Web UIs: Part Understanding HTML

WBOY
Release: 2024-08-16 17:01:43
Original
1069 people have browsed it

Web Development is one of the most in-demand skills today. It involves creating user-friendly and engaging websites that can be accessed via a browser. The first step in becoming a web developer is understanding HTML.

Develop yourself to build Web UIs: Part  Understanding HTML

HTML (Hyper Text Markup Language) is the backbone of any web page. It’s the standard language used to structure a webpage, determining how content is displayed in browser. While the appearance of a page is decided by CSS (Cascading Style Sheets) and its functionality by JS (Javascript), HTML is responsible for the fundamental skeleton or structure.

Before diving in this part of the course, it’s important to understand famous and recurring jargons that will be used in your journey. These will help you understand the concepts as we progress (and also make it easy for the author to explain things ;-) ).


Understanding the Jargons

  1. Programming Language: A set of instructions written in a specific syntax (way of a programming language) that a computer can execute. Remember the computer understands only binary code (either 1 or 0), now, in order to make the computer understand the logic and also to find a trade-off, we (humans), have created a programming language such that it is easy for us to code and also for the computer to understand it.
  2. Compiler: A tool that translates code written in a programming language into machine language that a computer can understand and execute.
  3. Syntax: The rules that define the structure of a programming language. Think of it as the way words are arranged in a sentence to make sense.
  4. Comments: Notes within the code that explain what certain parts of the code do. Comments help other developers (or your future self) understand the logic behind your code.
  5. DOM (Document Object Model): The DOM is a tree-like representation of the HTML document. Every tag in your HTML becomes a node in this tree. For example, if your HTML has a tag with a

    (paragraph) inside it, the browser creates a body node with a paragraph node as its child.

  6. Children: You will understand this as you progress. Elements nested within another element. For example, in HTML, a paragraph tag (

    ) within a div tag (

    ) would be considered a child of the div.
  7. Block-level element: You will be introduced to this jargon as you progress. This term usually describes the feature of the element that it will be taking the full available width.

Firing up with HTML

HTML stands for Hyper Text Markup Language

  • Hyper Text: Refers to the ability of HTML to link different documents together.

  • Markup Language: Uses tags to annotate text, defining how it should be displayed in a browser.

Here’s the basic structure of an HTML document:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Tutorial</title>
  </head>
  <body>
    <p>Hello, world!</p>
  </body>
</html>
Copy after login
  • Tags: In HTML, tags are used to define elements. Tags are enclosed in angle brackets, like or

    .

  • Elements: Consist of an opening tag and a closing tag, which may contain content. For example,

    Hello, world!

    is a paragraph element.


HTML Document Structure

Every HTML document follows a basic structure:

  1. : Declares the document type and version of HTML.
  2. : The root element that encloses all other HTML elements.
  3. : Contains meta-information about the document, such as the title and links to stylesheets.
  4. : Sets the title of the webpage, displayed in the browser's title bar or tab.
  5. : Provides metadata about the HTML document, such as character set, author, and viewport settings. It's a self-closing tag.
  6. : Embeds CSS code to style the HTML elements.
  7. <script></script>: Embeds JavaScript code for adding interactivity to the webpage.
  8. : Encloses the content that will be visible to users on the webpage.

Commonly Used HTML Elements

Here are some basic HTML elements you’ll use frequently:

  • : Defines a paragraph.
  • : A block-level element used to group other elements together.
  • : An inline element used to group text for styling purposes.
  • : Represents the introductory content or navigational links of a section.
  • to
    : Headings, with

    being the highest level and

    the lowest.

  • : Inserts a line break (self-closing tag — meaning there is no need to close the tag).
  • : Used to create an HTML form for user input.
  • : Creates an input field, typically used within a form.
  • : Creates a dropdown list.
  • : Associates a text label with a form element.
  • : Defines a table.
  • : Defines a row in a table.
  • : Defines a cell in a table row.
  • : Defines a header cell in a table row.
    • : Defines an unordered (bulleted) list.
      1. : Defines an ordered (numbered) list.
      2. : Defines a list item.

      Creating Your First HTML File

      To create an HTML file, you can use any text editor, such as Notepad or VS Code. Here’s a simple example:

      1. Open your text editor and type the following code:
      <!DOCTYPE html>
      <html>
      <head>
        <title>HTML Tutorial</title>
      </head>
      <body>
        <h1>Example Number 1</h1>
        <p>Hello, world!</p>
      </body>
      </html>
      
      Copy after login
      1. Save the file with a .html extension (e.g., index.html)
      2. Open the file in your web browser to see your first HTML webpage in action!
      3. To inspect your code, press Ctrl + Shift + C in Google Chrome to open the Developer Tools and explore the DOM structure.
      4. Go to the network tab in the Developer Tools and refresh your browser tab.

      You can find that there is a request in the name that you have saved as in this picture.
      Develop yourself to build Web UIs: Part  Understanding HTML

      In the response tab, you will find the code that you have written as in the following picture
      Develop yourself to build Web UIs: Part  Understanding HTML

      Now, what happened is that, once you opened the file you have saved as html, the computer began running the file in browser. The browser wanted something to show, so it made a request call to the file from which it was launched. The file gave the browser your code and that was found in the response section. Since it was a html file, the browser begins reading the HTML code from the top to the bottom. This process is known as parsing. During parsing, the browser encounters different HTML tags (like , , , etc.) and starts to build a structure called DOM based on these tags. As the browser builds the DOM, it simultaneously renders the content on your screen.


      Creating a Table

      Let’s take a step further by creating a simple table in HTML:

      1. Open the same HTML file and add the following code inside the tag:
      <p>Table Example</p>
      <table>
        <tr>
          <th>Name</th>
          <th>Power</th>
          <th>Is Kurama Present</th>
        </tr>
        <tr>
          <td>Naruto</td>
          <td>Rasengan</td>
          <td>Yes</td>
        </tr>
        <tr>
          <td>Sasuke</td>
          <td>Sharingan</td>
          <td>No</td>
        </tr>
      </table>
      
      Copy after login
      1. Save the file and refresh your browser to see the table displayed.

      Notice the heading is being rendered by paragraph tag. Alternatively, you can also use tag, which will center the heading of the table. Experiment with the caption tag and refresh to see the changes.

      Note that tag should only be used immediately after the

      opening tag.

      You’ve now successfully created a basic table in HTML. Feel free to experiment with additional rows and columns to get more comfortable with HTML syntax.


      Conclusion

      Congratulations on completing your first steps into web development with HTML! The key to mastering HTML is practice. Experiment with different elements, create your own webpages, and don’t be afraid to make mistakes — every error is a learning opportunity.

      Remember, this is just the beginning. As you continue to build on this foundation, you’ll soon be able to create more complex and dynamic websites. Let’s make the web a better place, one line of code at a time.

      This article is written by Anantha Krishnan, a professional with experience in both IT and Mechanical Engineering. With a background in full stack development and a passion for mechanical and electrical systems, Anantha Krishnan is now focused on creating educational content to help beginners in fields of his expertise.

      The above is the detailed content of Develop yourself to build Web UIs: Part Understanding HTML. For more information, please follow other related articles on the PHP Chinese website!

      source:dev.to
      Statement of this Website
      The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
      Popular Tutorials
      More>
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!