Home  >  Article  >  Web Front-end  >  How to set text spacing in css

How to set text spacing in css

青灯夜游
青灯夜游Original
2021-03-31 17:09:0938133browse

You can use the letter-spacing attribute to set the text spacing in css. You only need to add the "letter-spacing:length value;" style to the text element. The letter-spacing property is used to increase or decrease the space between characters; negative values ​​are allowed, but will cause letters to be squeezed closer together.

How to set text spacing in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

css sets text spacing

In CSS, the property for adjusting the spacing between words is letter-spacing. You change the letter-spacing property of the label. Value to set the spacing between words within the label.

The letter-spacing property increases or decreases the space between characters (character spacing).

This property defines how much space is inserted between text character boxes. Because character glyphs are typically narrower than their character boxes, specifying a length value adjusts the usual spacing between letters. Therefore, normal is equivalent to a value of 0. [Recommended tutorial: CSS video tutorial]

Note: Negative values ​​are allowed, which will make the letters squeeze closer together.

Attribute value:

How to set text spacing in css

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			h1 {
				letter-spacing: 3px;
			}
			
			h2 {
				letter-spacing: -3px;
			}
			div{
				letter-spacing: 3px;
			}
			p{
				letter-spacing: -3px;
			}
		</style>
	</head>

	<body>
		<h1>This is heading 1</h1>
		<h2>This is heading 2</h2>
		<div>这是一段测试文本!</div>
		<p>这是一段测试文本!</p>
	</body>

</html>

Rendering:

How to set text spacing in css

For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of How to set text spacing in css. 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