Как сделать шрифт курсивом в html
Перейти к содержимому

Как сделать шрифт курсивом в html

  • автор:

# Text Formatting

While most HTML tags are used to create elements, HTML also provides in-text formatting tags to apply specific text-related styles to portions of text. This topic includes examples of HTML text formatting such as highlighting, bolding, underlining, subscript, and stricken text.

# Highlighting

The <mark> element is new in HTML5 and is used to mark or highlight text in a document "due to its relevance in another context". 1

The most common example would be in the results of a search were the user has entered a search query and results are shown highlighting the desired query.

Black text on yellow background is a common default style for the mark element

A common standard formatting is black text on a yellow background, but this can be changed with CSS.

# Bold, Italic, and Underline

# Bold Text

To bold text, use the <strong> or <b> tags:

What’s the difference? Semantics. <strong> is used to indicate that the text is fundamentally or semantically important to the surrounding text, while <b> indicates no such importance and simply represents text that should be bolded.

If you were to use <b> a text-to-speech program would not say the word(s) any differently than any of the other words around it — you are simply drawing attention to them without adding any additional importance. By using <strong> , though, the same program would want to speak those word(s) with a different tone of voice to convey that the text is important in some way.

# Italic Text

To italicize text, use the <em> or <i> tags:

What’s the difference? Semantics. <em> is used to indicate that the text should have extra emphasis that should be stressed, while <i> simply represents text which should be set off from the normal text around it.

For example, if you wanted to stress the action inside a sentence, one might do so by emphasizing it in italics via <em> : "Would you just submit the edit already?"

But if you were identifying a book or newspaper that you would normally italicize stylistically, you would simply use <i> : "I was forced to read Romeo and Juliet in high school.

# Underlined Text

While the <u> element itself was deprecated in HTMl 4, it was reintroduced with alternate semantic meaning in HTML 5 — to represent an unarticulated, non-textual annotation. You might use such a rendering to indicate misspelled text on the page, or for a Chinese proper name mark.

# Abbreviation

To mark some expression as an abbreviation, use <abbr> tag:

If present, the title attribute is used to present the full description of such abbreviation.

# Inserted, Deleted, or Stricken

To mark text as inserted, use the <ins> tag:

To mark text as deleted, use the <del> tag:

To strike through text, use the <s> tag:

# Superscript and Subscript

To offset text either upward or downward you can use the tags <sup> and <sub> .

CSS Basics for Typography

Elad Shechter

In 2020 there are a lot of developers and designers who want to learn the basics of CSS. In this series of articles, I will teach you those main topics. In this specific article, I will review the essential CSS properties of typography while using many visual examples.

font-family

This font-family property is used to declare what font we want to use. It can receive an array of fonts. This can be useful to us for two reasons:

  1. If the first font isn’t working in a specific operating system, the browser will use the next font until something matches it.
  2. If the font has missed some of the characters, it will fill in the missing characters from the next font at the list.

font-weight

This property, like his name, is for declaring the font-weight of the text. The default value of this property is normal , and the second common value of it is bold .

In more advanced fonts there are more than two states. Instead of using names in the values, these fonts are using numeric values: 100 / 200 / 300 / 400 / 500 / 600 / 700 / 800 / 900 and 950 . Which are equal to the common mapping names (in design apps), see table:

The normal keyword is equal to 400 value, and the bold keyword is equal to 700 value. Examples:

font-size

This property, like his name, is for declaring the font-size of the text. Even today, the most common sizing unit is pixels. Example:

From my perspective, it is better to control the font-size with rem units. If you want to know more about how to work with rem units, you can read my article “Update your font-size to REM units”.

line-height

This property is telling the browser the height of the line in ratio to the text-size . This property can get fixed value like pixel, but the most common way is to give it a value of ratio without any unit.

The line-height property, is a type of inherited property, which usually means you declare it one time in the root element, and it will affect all the elements on our website. This way if we have different font-size in inner elements, the line-height will stay with the same ratio, and we won’t need to declare it multiple times. Example:

font-style

We use it to update the text font into an italic variant state.

Text color property

The color property is used to color the text. It can receive color keywords, for example, red , magenta . It can receive a HEX color code and color functions like RGB and HSL. If you want to know more about CSS colors, you can read my article “Why CSS HSL Colors are Better!”.

text-align

This property, like his name, is to control the alignment of text in its reading axis(inline-axis). Besides the possibilities to align left and right , we have the center value and the less known justify value, which aligns the text in both ways.

Besides, there is an extensive property, text-align-last , which allows you to differentiate the last line from all the other lines. For more info: text-align-last in MDN.

direction

The direction property sets the direction of text, table columns, flexbox, grids, and more. It has two values:

  1. ltr value — for Latin languages that are read from left to right.
  2. rtl value — for Semitic languages that are read from right to left.

When using the direction property the text-align property is being updated automatically as well in the same direction unless it is defined otherwise. Example:

vertical-align

This property is used mainly for vertical inline text content. The main common values are baseline (default value), text-top , and text-bottom which are relative to the line-height of the text in the container.

There are more values like top and bottom that can act differently only if the line-height of to row is different from the line-height of the inline elements.

This property can be used even unit values which are positioned according to the baseline value, which means 0px = baseline , with this, you can play with negative & positive values, for example -2px or 2px .

Note: this vertical alignment is good for text elements. For vertical alignment of boxes, it is better to use CSS flexbox.

text-decoration

This property’s most used case is for adding underline to links, and it could also be used for creating overline and line-through . Example:

But in the last years, this property has been given a lot of extensions, and now you can use all the values together, for example:

Another possibility we now have is to play with the style of the lines and with their color.

text-transform

The text-transform property specifies how to capitalize on texts. We use it to make text appear in all-uppercase or all-lowercase, or to make each word capitalized.

letter-spacing

The letter-spacing property, as his name is, decreases or increases the spacing between the letters of the words. When using this property with px units, you can use fragments of pixels for example 0.1px . To decrease the spacing, this property can get negative values as well, like -1.5px , for example.

word-spacing

The letter-spacing property, as his name, allows us to define the space between the words.

text-indent

The indent property is used to indent the first line in a paragraph. Inside with a positive value or outside with a negative value.

::first-letter

The ::first-letter pseudo-element selector allows us to style the first letter in different styles from the regular text in paragraphs, for example.

Besides the ::first-letter pseudo-element, there is the ::first-line pseudo-element, which allows you to style the first-line of a paragraph differently. Because I haven’t seen a common use for it, I have decided not to give it a big stage in my article, but just to notify you that it exists.

text-shadow

The text-shadow property allows us to add shadow to text. For it to work, we need to provide it with at least the offset-x and the offset-y of the shadow. If we provide only these two values, the shadow will be left without a spread and with the same color of the text.

The third numeric value will be the spread of the shadow. We can also give it a different color value, in the beginning, or the end of the value.

Besides, we can add multiple text-shadows, using a comma in the value.

text-stroke

The text-stroke property is a non-standard property that works in all main browsers. It works with the -webkit prefix, even on Firefox & old Edge. The property receives two values, stroke-width and stroke-color.

More and More and More!

There are more properties of CSS for typography and big new topics like Variable Fonts, which are dynamic. But in this article, I have tried to show the main basic elements to control typography with CSS.

If this topic interests you, you can continue and explore this vast topic in CSS. Here some more properties and topics we haven’t talked about: Variable Fonts, font-variant , text-justify , unicode-bidi , all the ways of breaking words in CSS, and I may have missed several more��.

To Summarize

In this article, my primary purpose was to show the most useful properties for CSS typography and to provide you with this knowledge.

Final Words

I hope I inspired you and showed you some new possibilities.
If you like this post, I would appreciate applause and sharing ��.

I create lots of content on CSS. Be sure to follow me via Twitter, Linkedin, and Medium.

Also, you can see all of my content on my website: eladsc.dev.

Who Am I?

I am Elad Shechter, a Web Developer specializing in CSS & HTML design and architecture.

font-style

font-style это CSS-свойство определяющее каким образом шрифт должен быть стилизирован, будь то это normal, italic, или oblique face из его font-family .

Интерактивный пример

Italic шрифты в общем курсивные по своей сути, обычно занимают меньше горизонтального пространства чем их нестилизированные копии, тогда как oblique шрифты обычно просто наклонная версия регулярного шрифта. Когда определённый стиль не доступен, оба italic и oblique шрифты симулируются искусственно наклоняя глифы регулярного шрифта (используйте font-synthesis (en-US) для управления этим поведением).

Syntax

Свойство font-style определяется как единственное ключевое слово выбранное из списка значений внизу.

Values

Выделяет шрифт который классифицирован как normal в font-family .

Выделяет шрифт который классифицирован как italic . Если не доступна курсивная версия шрифта, взамен используется oblique классификация. Если не одна версия не доступна, то стиль симулируется искусственно.

Выделяет шрифт который классифицирован как oblique . Если не доступна косая версия шрифта, взамен используется italic классификация. Если не одна версия не доступна, то стиль симулируется искусственно.

Тег <i> HTML курсив

+++--

Тег <i> в HTML используется для выделения фрагмента текста курсивом.

HTML тег <i> относится к тегам физического форматирования. Изменение начертания шрифта с помощью тега <i> носит стилистический характер.

Сделать HTML текст курсивом можно также с помощью тега <em> . При этом текст будет считаться, выделенным логически (по смыслу), «подчеркнутым».

Спецификация HTML5 рекомендует отдавать приоритет тегам логического форматирования: важные фрагменты текста — тег <strong> , акцентирование внимания — тег <em> , подзаголовки — теги <h1> — <h6> , подсветка текста — тег <mark> . Выделять текст курсивом с помощью тега <i> следует только если характер выделения не соответствует ни одному тегу логического форматирования.

Все виды выделения текста описаны в статье: Теги форматирования текста в HTML.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *