DEV Community

Cover image for Develop yourself to build Web UIs: Part 1 : Understanding HTML
Marina LABS
Marina LABS

Posted on

Develop yourself to build Web UIs: Part 1 : Understanding HTML

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.

Web UI Template

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 <body> tag with a <p> (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 (<p>) within a div tag (<div>) 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>
Enter fullscreen mode Exit fullscreen mode
  • Tags: In HTML, tags are used to define elements. Tags are enclosed in angle brackets, like <html> or <p>.

  • Elements: Consist of an opening tag and a closing tag, which may contain content. For example, <p>Hello, world!</p> is a paragraph element.


HTML Document Structure

Every HTML document follows a basic structure:

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

  • <p></p>: Defines a paragraph.
  • <div></div>: A block-level element used to group other elements together.
  • <span></span>: An inline element used to group text for styling purposes.
  • <header></header>: Represents the introductory content or navigational links of a section.
  • <h1></h1> to <h6></h6>: Headings, with <h1> being the highest level and <h6> the lowest.
  • <br>: Inserts a line break (self-closing tag — meaning there is no need to close the tag).
  • <form></form>: Used to create an HTML form for user input.
  • <input>: Creates an input field, typically used within a form.
  • <select></select>: Creates a dropdown list.
  • <label></label>: Associates a text label with a form element.
  • <table></table>: Defines a table.
  • <tr></tr>: Defines a row in a table.
  • <td></td>: Defines a cell in a table row.
  • <th></th>: Defines a header cell in a table row.
  • <ul></ul>: Defines an unordered (bulleted) list.
  • <ol></ol>: Defines an ordered (numbered) list.
  • <li></li>: 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>
Enter fullscreen mode Exit fullscreen mode
  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.
Request in the network tab

In the response tab, you will find the code that you have written as in the following picture
Response in the network tab

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 <html>, <head>, <body>, 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 <body> 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>
Enter fullscreen mode Exit fullscreen mode
  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 <caption> tag, which will center the heading of the table. Experiment with the caption tag and refresh to see the changes.

Note that <caption> tag should only be used immediately after the <table> 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.

Top comments (0)