search
HomeWeb Front-endCSS TutorialHow to set line spacing using CSS line-height property

The implementation of line spacing in CSS requires the How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property attribute. The following article will introduce to you the specific method of using the How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property attribute in CSS.

How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property

Sometimes the interval between characters is too large or too narrow, which may not be certain. We need to adjust it according to the needs of the website, and use CSS How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property Properties can adjust the distance between characters.

Let’s take a look at a specific example

Let’s first create the following HTML code (the default browser size is 16px)

HTML code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="sample.css" type="text/css">
</head>
<body>
<p class="sample1">冬天的百草园比较的无味;雪一下,可就两样了。拍雪人(将自己的全形印在雪上)和塑雪罗汉需要人们鉴赏,这是荒园,人迹罕至,所以不相宜,只好来捕鸟。薄薄的雪,是不行的;总须积雪盖了地面一两天,鸟雀们久已无处觅食的时候才好。扫开一块雪,露出地面,用一支短棒支起一面大的竹筛来,下面撒些秕谷,棒上系一条长绳,人远远地牵着,看鸟雀下来啄食,走到竹筛底下的时候,将绳子一拉,便罩住了。 </p>
<p class="sample2">先生读书入神的时候,于我们是很相宜的。有几个便用纸糊的盔甲套在指甲上做戏。我是画画儿,用一种叫作“荆川纸”的,蒙在小说的绣像上一个个描下来,象习字时候的影写一样。读的书多起来,画的画也多起来;书没有读成,画的成绩却不少了,最成片断的是《荡寇志》和《西游记》的绣像,都有一大本。 </p>
</body>
</html>

Next we apply the How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property attribute in CSS

We first set the value of the How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property attribute to normal

CSS code

p.sample1 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:normal; }
p.sample2 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:normal; }

This state is the default state, so the character spacing has not changed.

The effect is as follows

How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property

We will use the following three units to set them separately. Line spacing

Use px settings

The CSS code is as follows

p.sample1 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:20px; }
p.sample2 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:50px; }

The display effect on the browser is as follows. Setting the value with How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property (here the default is 16 px) will distribute the value equally up and down. Therefore, the larger the number, the wider the spacing between rows.

How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property

Setting with em

The following is an example of setting the line spacing in units of em (Em). em is a unit of 1 based on the size specified by the font-size attribute. If it is not specified in the parent element, it is 1 em = 16px.

CSS code is as follows

p.sample1 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:2em; }
p.sample2 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:4em; }

The display effect on the browser is as follows

The larger the value specified here, the larger the line spacing. The default is 16px, where 2em = 32px, 4em = 64px.

How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property

Set with %

Finally set with %. The size specified by the font-size attribute is 100%, and the line spacing is set by the specified % value. If there is no parent element set, 100% = 16px.

The CSS code is as follows

p.sample1 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:150%; }
p.sample2 {How to set line spacing using CSS How to set line spacing using CSS How to set line spacing using CSS line-height property property property:200%; }

The following effect is displayed on the browser

How to set line spacing using CSS line-height property

The above is the detailed content of How to set line spacing using CSS line-height property. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
The Lost CSS Tricks of Cohost.orgThe Lost CSS Tricks of Cohost.orgApr 25, 2025 am 09:51 AM

In this post, Blackle Mori shows you a few of the hacks found while trying to push the limits of Cohost’s HTML support. Use these if you dare, lest you too get labelled a CSS criminal.

Next Level CSS Styling for CursorsNext Level CSS Styling for CursorsApr 23, 2025 am 11:04 AM

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Worlds Collide: Keyframe Collision Detection Using Style QueriesWorlds Collide: Keyframe Collision Detection Using Style QueriesApr 23, 2025 am 10:42 AM

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Using CSS backdrop-filter for UI EffectsUsing CSS backdrop-filter for UI EffectsApr 23, 2025 am 10:20 AM

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

SMIL on?SMIL on?Apr 23, 2025 am 09:57 AM

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

'Pretty' is in the eye of the beholder'Pretty' is in the eye of the beholderApr 23, 2025 am 09:40 AM

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

CSS-Tricks Chronicles XLIIICSS-Tricks Chronicles XLIIIApr 23, 2025 am 09:35 AM

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Tailwind's @apply Feature is Better Than it SoundsTailwind's @apply Feature is Better Than it SoundsApr 23, 2025 am 09:23 AM

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.