Home Web Front-end HTML Tutorial Three ways to make fonts bold in HTML and CSS

Three ways to make fonts bold in HTML and CSS

Oct 31, 2018 pm 03:05 PM
css html

Have you noticed when browsing the website that some text or fonts on the page are bolded? Friends who are learning HTML and CSS, do you know how to bold text in HTML? How to set font boldness in CSS? This article summarizes three ways to bold fonts and text, including bold tags in HTML and CSS font bold styles. It has certain reference value and interested friends can refer to it.

There are three ways to bold fonts and text. One is the font-weight: bold style in CSS, the other is the tag in HTML, and the last one is The tag in HTML.

Method 1: Use the font-weight: bold style in CSS to make the font bold

The font-weight attribute can set the thickness of the font, when the attribute value is normal , indicating a normal font, which is equivalent to a number of 400; when the attribute value is bold, the font can be bold, which is equivalent to a number of 700, which is also equivalent to the effect of the tag.

Instance description: Create two p tags and give one of the tags a class name to facilitate CSS styling. Add the font-weight: bold attribute to the p tag with the class name, and compare the two p tags to see the difference. The specific code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.aa{font-weight: bold;}
</style>
</head>
<body>
<p>床前明月光</p>
<p class="aa">低头思故乡</p>
</body>
</html>

As shown in the figure below, "bow down and think about hometown" This text is bolded.

Three ways to make fonts bold in HTML and CSS

##Method 2: Use the bold tag in HTML

tag can make the font bold Coarse, and all major browsers support this method.

Example description: Directly use the tag in HTML to achieve the text bolding effect. The specific code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>床前明月光</p>
<strong>疑是地上霜</strong>
</body>
</html>

As shown in the figure, compare the p tag and the strong tag content, I found that the content of the strong tag was bolded.

Three ways to make fonts bold in HTML and CSS

Method 3: Use the bold tag in HTML

tag can define a bold font text, and all major browsers support the tag.

Example description: The tag is the same as the tag. You can bold text, and it is simple and convenient to use. The specific code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>床前明月光</p>
<b>举头望明月</b>
</body>
</html>
As shown in the picture below, the text in the b tag is bolded

Three ways to make fonts bold in HTML and CSS

Summary: The above introduces you to three methods of bolding text. , respectively the font-weight: bold style in CSS and the tag and tag in HTML. It is more convenient to use html tags directly. As for which method to choose, it depends on personal habits and work needs. Hope this article helps you!

[Related tutorial recommendations]

1,

Three ways to add strikethrough to text in HTML and CSS (pictures and text)

2.​

HTMLTutorial

3.

HTML Online Manual

The above is the detailed content of Three ways to make fonts bold in 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 Article

Peak: How To Revive Players
1 months ago By DDD
PEAK How to Emote
4 weeks ago By Jack chen

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 to create responsive images using CSS? How to create responsive images using CSS? Jul 15, 2025 am 01:10 AM

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

Describe the `opacity` property Describe the `opacity` property Jul 15, 2025 am 01:23 AM

opacity is an attribute in CSS that controls the overall transparency of an element, with values ranging from 0 (fully transparent) to 1 (fully opaque). 1. It is often used for the image hover fade effect, and enhances the interactive experience by setting the opacity transition; 2. Making a background mask layer to improve text readability; 3. Visual feedback of control buttons or icons in the disabled state. Note that it affects all child elements, unlike rgba, which only affects the specified color part. Smooth animation can be achieved with transition, but frequent use may affect performance. It is recommended to use it in combination with will-change or transform. Rational application of opacity can enhance page hierarchy and interactivity, but it should avoid interfering with users.

Explain property inheritance in CSS Explain property inheritance in CSS Jul 15, 2025 am 01:25 AM

InCSS,propertyinheritanceaffectshowstylesarepassedfromparentelementstochildren.Somepropertieslikecolorandfont-familyinheritbydefault,applyingtoallnestedelementsunlessoverridden.Non-inheritedpropertiessuchasborder,margin,andpaddingmustbesetexplicitly.

Specifying Character Encoding for HTML Documents (UTF-8) Specifying Character Encoding for HTML Documents (UTF-8) Jul 15, 2025 am 01:43 AM

To correctly set the character encoding of the HTML document to UTF-8, you need to follow three steps: 1. Add at the top of the HTML5 part; 2. Configure the response header Content-Type: text/html; charset=UTF-8, if Apache uses AddDefaultCharsetUTF-8, Nginx uses charsetutf-8; 3. Select the UTF-8 encoding format when saving HTML files in the editor. These three links are indispensable, otherwise it may lead to garbled page code and failure of special character parsing, affecting user experience and SEO effect. It is important to ensure that HTML declaration, server configuration and file saving are consistent.

How do you use multiple background images on a single element? How do you use multiple background images on a single element? Jul 15, 2025 am 12:59 AM

The key to setting multiple background images for elements in CSS is to use comma separation and attribute order correctly. 1. Use the background-image attribute and use commas to separate multiple image addresses. The first image is displayed on the top layer; 2. Use background-repeat, background-position and other attributes to control the display method of each image, and the values of each attribute correspond to each image in order; 3. You can also use the background abbreviation attribute to define all parameters at once to improve code readability and maintenance; 4. Actual applications include buttons and icons, decorative borders, page title bars and other effects. You can master the corresponding relationship between the order and attributes and use them flexibly.

How to style selection highlighting (`::selection`)? How to style selection highlighting (`::selection`)? Jul 16, 2025 am 12:50 AM

Use the ::selection pseudo-element of CSS to customize the highlighting style when the web page text is selected to improve the aesthetics and unity of the page. 1. Basic settings: define background-color and color through ::selection, such as yellow background with dark gray fonts; specific elements such as p::selection can also be limited. 2. Compatibility processing: Add the -webkit- prefix to be compatible with Safari and mobile browsers, and the Firefox and Edge standards are well supported. 3. Pay attention to readability: Avoid excessive color contrast or too fancy, and should be coordinated with the overall design. For example, choose a soft blue base in dark mode to improve visual comfort. Reasonable use can enhance the texture of the interface, ignore details

How to style the first letter or first line of a paragraph? How to style the first letter or first line of a paragraph? Jul 19, 2025 am 02:58 AM

To beautify the beginning of a paragraph to enhance visual appeal, a common practice is to use pseudo-elements of CSS or manually style the document. In web development, p::first-letter can be used to set the first letter style, such as enlarging, bolding, and discoloring, but it should be noted that it is only suitable for block-level elements; if you want to highlight the entire first line, use p::first-line to add styles; in document software such as Word, you can manually adjust the first letter format or create style templates, and InDesign has a built-in "first-sinking" function suitable for publishing and design; when applying, you need to pay attention to details, such as avoiding complex styles affecting reading and ensuring compatibility and format consistency.

Describe the `word-break` and `word-wrap` properties Describe the `word-break` and `word-wrap` properties Jul 16, 2025 am 02:08 AM

Word-break and overflow-wrap (formerly word-wrap) do differently when dealing with long words or unbreakable content. 1. Word-break controls how to break lines of words in block elements, break-all forces long words to break, keep-all avoids breaking, suitable for Chinese, Japanese and Korean texts. 2. Overflow-wrap disconnects long words when necessary to prevent overflow, break-word makes the context more intelligent. 3. In usage scenarios, use word-break:break-all for code, and use overflow-wrap:break-word for user comments. 4. Pay attention to differences in browser compatibility and different mobile behaviors

See all articles