Front-end/HTML,CSS,JavaScript

HTML Fundamentals 1/

metamong 2023. 3. 29.

1. HTML Intro

① HTML stands for Hyper Text Markup Language

② HTML is the standard markup language for creating Web pages

③ HTML describes the structure of a Web page

④ HTML consists of a series of elements

⑤ HTML elements tell the browser how to display the content

⑥ HTML elements label pieces of content such as "this is a heading", "this is a paragraph", "this is a link", etc.

⑦ HTML is not case sensitive - W3C recommends lowercase in HTML

*simple example

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

 

→ The <!DOCTYPE html> declaration defines that this document is an HTML5 document

→ The <html> element is the root element of an HTML page

→ The <head> element contains meta information about the HTML page

→ The <title> element specifies a title for the HTML page (which is shown in the browser's title bar or in the page's tab)

→ The <body> element defines the document's body, and is a container for all the visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.

→ The <h1> element defines a large heading

→ The <p> element defines a paragraph

* HTML element

An HTML element is defined by a start tag, some content, and an end tag:

 

<tagname> Content goes here... </tagname>

 

Note: Some HTML elements have no content (like the <br> element). These elements are called empty elements. Empty elements do not have an end tag!

* HTML Page Structure

Below is a visualization of an HTML page structure:

 

Note: The content inside the <body> section (the white area above) will be displayed in a browser. The content inside the <title> element will be shown in the browser's title bar or in the page's tab.

2. HTML Basic

* The <!DOCTYPE> Declaration

The <!DOCTYPE> declaration represents the document type, and helps browsers to display web pages correctly.

 

It must only appear once, at the top of the page (before any HTML tags).

 

The <!DOCTYPE> declaration is not case sensitive.

 

The <!DOCTYPE> declaration for HTML5 is:

<!DOCTYPE html>

* HTML Headings

HTML headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the least important heading:

<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>

* HTML Paragraphs

HTML paragraphs are defined with the <p> tag

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

* HTML Links

HTML links are defined with the <a> tag

<a href="https://www.w3schools.com">This is a link</a>

* HTML Images

HTML images are defined with the <img> tag.

The source file (src), alternative text (alt), width, and height are provided as attributes:

<img src="images/metamong.jpg" alt="An image of metamong" width="104" height="142">

3. HTML Attributes

→ All HTML elements can have attributes

→ Attributes provide additional information about elements

→ Attributes are always specified in the start tag

→ Attributes usually come in name/value pairs like: name="value"

* href Attribute

The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to

<a href="https://www.w3schools.com">Visit W3Schools</a>

* src Attribute

The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed

<img src="img_girl.jpg">

 

→ 2 ways to specify the URL in the src attribute:

Absolute URL: Links to an external image that is hosted on another website. Example: src="https://www.w3schools.com/images/img_girl.jpg".

Relative URL: Links to an image that is hosted within the website. Here, the URL does not include the domain name. If the URL begins without a slash, it will be relative to the current page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be relative to the domain. Example: src="/images/img_girl.jpg".

(Tip: It is almost always best to use relative URLs. They will not break if you change domain.)

* width & height Attributes

The <img> tag should also contain the width and height attributes, which specify the width and height of the image (in pixels)

<img src="img_girl.jpg" width="500" height="600">

* alt Attribute

The required alt attribute for the <img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to a slow connection, or an error in the src attribute, or if the user uses a screen reader.

<img src="img_girl.jpg" alt="Girl with a jacket">

* style Attribute

The style attribute is used to add styles to an element, such as color, font, size, and more.

<p style="color:red;">This is a red paragraph.</p>

* lang Attribute

You should always include the lang attribute inside the <html> tag, to declare the language of the Web page. This is meant to assist search engines and browsers.

 

The following example specifies English as the language:

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

Country codes can also be added to the language code in the lang attribute. So, the first two characters define the language of the HTML page, and the last two characters define the country.

 

The following example specifies English as the language and United States as the country:

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

* title Attribute

The title attribute defines some extra information about an element.

The value of the title attribute will be displayed as a tooltip when you mouse over the element:

<p title="I'm a tooltip">This is a paragraph.</p>

4. HTML Headings / Paragraphs

* Headings

HTML headings are titles or subtitles that you want to display on a webpage.

 

HTML headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the least important heading.

 

* Headings are important!

Search engines use the headings to index the structure and content of your web pages.

Users often skim a page by its headings. It is important to use headings to show the document structure.

<h1> headings should be used for main headings, followed by <h2> headings, then the less important <h3>, and so on.

* Paragraphs

The HTML <p> element defines a paragraph.

A paragraph always starts on a new line, and browsers automatically add some white space (a margin) before and after a paragraph.

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

 

HTML display - You cannot be sure how HTML will be displayed. Large or small screens, and resized windows will create different results. With HTML, you cannot change the display by adding extra spaces or extra lines in your HTML code. The browser will automatically remove any extra spaces and lines when the page is displayed:

 

* HTML horizontal rules

The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a horizontal rule.

The <hr> element is used to separate content (or define a change) in an HTML page:

<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>

 

* HTML line breaks

The HTML <br> element defines a line break.

Use <br> if you want a line break (a new line) without starting a new paragraph:

<p>This is<br>a paragraph<br>with line breaks.</p>

 

* <pre> element

The HTML <pre> element defines preformatted text. The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks:

<pre>
  My Bonnie lies over the ocean.

  My Bonnie lies over the sea.

  My Bonnie lies over the ocean.

  Oh, bring back my Bonnie to me.
</pre>

* source 1) https://www.w3schools.com/html/html_intro.asp

 

 

 

댓글