国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end CSS Tutorial Fundamentals of HTML and CSS

Fundamentals of HTML and CSS

Jan 06, 2025 pm 10:11 PM

HTML and CSS are the most fundamental building blocks of a webpage, and they are also your first step towards becoming a web developer. HTML provides the layout and content of the webpage, and CSS defines its style and appearance. In this tutorial, we are going to cover the basics of HTML and CSS, and by the end, you will be able to design responsive webpages that work seamlessly on devices of all sizes.

What is HTML?

HTML is the standard markup language used to create webpages. It defines the structure and content of webpages using HTML elements such as headings, paragraphs, images, links, forms, and more.

To start writing HTML code, you can use the CodePen demo below:

Code Demo ?

On the left side, you will find the HTML source code, which is essentially the blueprint for what will be displayed. The browser will then transform this blueprint into the webpage you see on the right side.

You can modify the source code directly to see how it affects the displayed webpage.

Prepare your computer for web development

Of course, in practice, you cannot rely on tools such as CodePen to create a working and fully featured web application. You need something more powerful, so, let's set up your computer for web development.

To get started, make sure you have a browser installed. Any popular web browser such as Google Chrome, Microsoft Edge, Safari, or Firefox, should be sufficient for this course. You may download and install the browser from the linked websites.

In addition, you'll need a code editor to write and edit your code. Visual Studio Code is a great option for beginners (and professionals, for that matter). It is the most commonly used code editor in the world. Simply download the appropriate installer for your operating system from their official website.

Fundamentals of HTML and CSS

After you've installed VSCode, make sure to install the Live Server extension as well. Navigate to the Extensions tab on the left sidebar, and type in Live Server in the search box. From there, you'll be able to download and install the extension.

Fundamentals of HTML and CSS

Live Server will create a local development server with the auto-reload feature. For example, create a new work directory and open it using VSCode.

Fundamentals of HTML and CSS

Create a new file named index.html under this directory. The .html extension indicates that this is an HTML document. Type in ! in VSCode, and you will see suggestions like this:

Fundamentals of HTML and CSS

This is a shortcut for creating HTML documents quickly. You can navigate with the ↑ or ↓ keys. Select the first option, and the following code should be generated.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>

Notice that at the bottom right corner of the VSCode window, there is a Go Live button.

Fundamentals of HTML and CSS

Clicking this button will activate the Live Server extension. A local development server will be started, hosting the index.html file you just created.

Fundamentals of HTML and CSS

Of course, the file is still empty right now, so you can't see anything. Add something between the and tags.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    Hello, world!
  </body>
</html>

Save the changes, and the webpage will be automatically refreshed with the new content.

Fundamentals of HTML and CSS

The structure of an HTML document

A typical HTML document always has the following structure:

<!DOCTYPE html>
<html lang="en">
  <head>
    . . .
  </head>
  <body>
    . . .
  </body>
</html>

The tag defines the document type. When the web browser encounters , it understands that the page should be parsed and displayed according to the specifications of HTML5, the latest version of HTML standard. This ensures that modern browsers interpret the webpage's content and layout correctly.

Everything else in the file should be enclosed inside an element, defined by an opening tag () and a closing tag ().

lang is called an attribute, and it has the value "en". This tells the browser as well as the search engine that English is the primary language used for this webpage.

Inside the element, there are two child elements, and . contains metadata and other information about the HTML document. This information will not be displayed in the browser but is often used by search engines for SEO (Search Engine Optimization) purposes.

, on the other hand, contains the main content of the webpage that is visible to the users, and for that reason, it is also the part of the HTML file we are going to focus on in this course.

Elements and attributes

Let's take a closer look at the previous example and notice that the HTML document comprises different elements in a nested structure. In HTML, most elements have both an opening tag and a closing tag:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>

In this case, is the opening tag, and is the closing tag, and together, they form an HTML element. An element could hold textual content between the opening and closing tags.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    Hello, world!
  </body>
</html>

The element can also wrap around other elements, forming a nested structure.

<!DOCTYPE html>
<html lang="en">
  <head>
    . . .
  </head>
  <body>
    . . .
  </body>
</html>

Inside the opening tag, you can define attributes, which are used to specify additional information about the element, such as its class, id, and so on.

<tag>. . .</tag>

The attribute is usually in a key/value pair, and the value must always be enclosed inside matching quotes (double or single).

There are some exceptions to these general formats. For example, the
element, which creates a line break, does not need a closing tag. Some attributes, such as multiple, do not require a value. We will discuss these exceptions later in this course as we encounter them.

However, you should remember that if an element does require a closing tag, then it should never be left out. In most cases, the webpage could still render correctly, but as the structure of your HTML document grows more complex, unexpected errors may occur. Take a look at our best practice guidelines for writing HTML and CSS if you are interested.

Further readings

  • Introducing the Cascading Style Sheet (CSS)
  • Introduction to JavaScript
  • What is Responsive Design
  • How to Build Interactive Forms Using HTML and CSS

The above is the detailed content of Fundamentals of HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How can I include CSS only on some pages? How can I include CSS only on some pages? Jun 11, 2025 am 12:01 AM

There are three ways to selectively include CSS on a specific page: 1. Inline CSS, suitable for pages that are not frequently accessed or require unique styles; 2. Load external CSS files using JavaScript conditions, suitable for situations where flexibility is required; 3. Containment on the server side, suitable for scenarios using server-side languages. This approach can optimize website performance and maintainability, but requires balance of modularity and performance.

What is 'render-blocking CSS'? What is 'render-blocking CSS'? Jun 24, 2025 am 12:42 AM

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

How to use Lotties in Figma How to use Lotties in Figma Jun 14, 2025 am 10:17 AM

In the following tutorial, I will show you how to create Lottie animations in Figma. We'll use two colorful designs to exmplify how you can animate in Figma, and then I'll show you how to go from Figma to Lottie animations. All you need is a free Fig

Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Breaking Boundaries: Building a Tangram Puzzle With (S)CSS Jun 13, 2025 am 11:33 AM

We put it to the test and it turns out Sass can replace JavaScript, at least when it comes to low-level logic and puzzle behavior. With nothing but maps, mixins, functions, and a whole lot of math, we managed to bring our Tangram puzzle to life, no J

External vs. Internal CSS: What's the Best Approach? External vs. Internal CSS: What's the Best Approach? Jun 20, 2025 am 12:45 AM

ThebestapproachforCSSdependsontheproject'sspecificneeds.Forlargerprojects,externalCSSisbetterduetomaintainabilityandreusability;forsmallerprojectsorsingle-pageapplications,internalCSSmightbemoresuitable.It'scrucialtobalanceprojectsize,performanceneed

Does my CSS must be on lower case? Does my CSS must be on lower case? Jun 19, 2025 am 12:29 AM

No,CSSdoesnothavetobeinlowercase.However,usinglowercaseisrecommendedfor:1)Consistencyandreadability,2)Avoidingerrorsinrelatedtechnologies,3)Potentialperformancebenefits,and4)Improvedcollaborationwithinteams.

CSS Counters: A Step-by-Step Tutorial with Examples CSS Counters: A Step-by-Step Tutorial with Examples Jun 12, 2025 am 10:31 AM

CSSCounters is a tool for creating automatic numbers. 1. Basic usage: define and operate counters through counter-reset and counter-increment, such as "SectionX." before h2. 2. Advanced usage: Use nested counters to create complex numbers, such as chapter and section numbers. 3. Notes: Ensure the counter is reset correctly, optimize performance, and simplify counter logic. 4. Best practice: clear naming, define counters in CSS, and use counter-increment and counter-reset reasonably.

CSS Case Sensitivity: Understanding What Matters CSS Case Sensitivity: Understanding What Matters Jun 20, 2025 am 12:09 AM

CSSismostlycase-insensitive,butURLsandfontfamilynamesarecase-sensitive.1)Propertiesandvalueslikecolor:red;arenotcase-sensitive.2)URLsmustmatchtheserver'scase,e.g.,/images/Logo.png.3)Fontfamilynameslike'OpenSans'mustbeexact.

See all articles