Css text style

How to title case and other upper and lower case css tricks

Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL”
in the normative parts of this document
are to be interpreted as described in RFC 2119.
However, for readability,
these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative
except sections explicitly marked as non-normative, examples, and notes.

Examples in this specification are introduced with the words “for example”
or are set apart from the normative text with , like this:

This is an example of an informative example.

Informative notes begin with the word “Note”
and are set apart from the normative text with , like this:

# The Font Shorthand

With the syntax:

You can have all your font-related styles in one declaration with the shorthand. Simply use the property, and put your values in the correct order.

For example, to make all elements bold with a font size of 20px and using Arial as the font family typically you would code it as follows:

However with the font shorthand it can be condensed as follows:

Note: that since , , and are optional, the three of them are skipped in this example. It is important to note that using the shortcut resets the other attributes not given. Another important point is that the two necessary attributes for the font shortcut to work are and . If they are not both included the shortcut is ignored.

Initial value for each of the properties:

  • – depends on user agent

Usage notes

The element should only be used for typographical reasons—that is, to change the position of the text to comply with typographical conventions or standards, rather than solely for presentation or appearance purposes.

For example, to style the wordmark of a business or product which uses a raised baseline should be done using CSS (most likely vertical-align ) rather than . This would be done using, for example, vertical-align: super or, to shift the baseline up 50%, vertical-align: 50% .

Appropriate use cases for include (but aren’t necessarily limited to):

  • Displaying exponents, such as «x 3 .» It may be worth considering the use of MathML for these, especially in more complex cases. See Exponents under Examples below.
  • Displaying superior lettering, which is used in some languages when rendering certain abbreviations. For example, in French, the word «mademoiselle» can be abbreviated «M lle «); this is an acceptable use case. See Superior lettering for examples.
  • Representing ordinal numbers, such as «4 th » instead of «fourth.» See Ordinal numbers for examples.

CSS Справочники

CSS СправочникCSS ПоддержкаCSS СелекторыCSS ФункцииCSS ЗвукCSS Веб шрифтыCSS АнимацииCSS ДлиныCSS Конвертер px-emCSS Названия цветаCSS Значения цветаCSS по умолчаниюCSS Символы

CSS Свойства

align-content
align-items
align-self
all
animation
animation-delay
animation-direction
animation-duration
animation-fill-mode
animation-iteration-count
animation-name
animation-play-state
animation-timing-function
backface-visibility
background
background-attachment
background-blend-mode
background-clip
background-color
background-image
background-origin
background-position
background-repeat
background-size
border
border-bottom
border-bottom-color
border-bottom-left-radius
border-bottom-right-radius
border-bottom-style
border-bottom-width
border-collapse
border-color
border-image
border-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
border-left
border-left-color
border-left-style
border-left-width
border-radius
border-right
border-right-color
border-right-style
border-right-width
border-spacing
border-style
border-top
border-top-color
border-top-left-radius
border-top-right-radius
border-top-style
border-top-width
border-width
bottom
box-decoration-break
box-shadow
box-sizing
caption-side
caret-color
@charset
clear
clip
color
column-count
column-fill
column-gap
column-rule
column-rule-color
column-rule-style
column-rule-width
column-span
column-width
columns
content
counter-increment
counter-reset
cursor
direction
display
empty-cells
filter
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
float
font
@font-face
font-family
font-kerning
font-size
font-size-adjust
font-stretch
font-style
font-variant
font-weight
grid
grid-area
grid-auto-columns
grid-auto-flow
grid-auto-rows
grid-column
grid-column-end
grid-column-gap
grid-column-start
grid-gap
grid-row
grid-row-end
grid-row-gap
grid-row-start
grid-template
grid-template-areas
grid-template-columns
grid-template-rows
hanging-punctuation
height
hyphens
@import
isolation
justify-content
@keyframes
left
letter-spacing
line-height
list-style
list-style-image
list-style-position
list-style-type
margin
margin-bottom
margin-left
margin-right
margin-top
max-height
max-width
@media
min-height
min-width
mix-blend-mode
object-fit
object-position
opacity
order
outline
outline-color
outline-offset
outline-style
outline-width
overflow
overflow-x
overflow-y
padding
padding-bottom
padding-left
padding-right
padding-top
page-break-after
page-break-before
page-break-inside
perspective
perspective-origin
pointer-events
position
quotes
resize
right
tab-size
table-layout
text-align
text-align-last
text-decoration
text-decoration-color
text-decoration-line
text-decoration-style
text-indent
text-justify
text-overflow
text-shadow
text-transform
top
transform
transform-origin
transform-style
transition
transition-delay
transition-duration
transition-property
transition-timing-function
unicode-bidi
user-select
vertical-align
visibility
white-space
width
word-break
word-spacing
word-wrap
writing-mode
z-index

Examples

This demonstrates no text transformation.

This demonstrates text capitalization.

This demonstrates how initial punctuations of a word are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.

This demonstrates how initial symbols are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.

This demonstrates how the Dutch ij digraph must be handled like one single letter.

This demonstrates transforming the text to uppercase.

This demonstrates how Greek vowels except disjunctive eta should have no accent, and the accent on the first vowel of a vowel pair becomes a diaeresis on the second vowel.

This demonstrates transforming the text to lowercase.

This demonstrates how the Greek character sigma () is transformed into the regular lowercase sigma () or the word-final variant (), according the context.

This demonstrates how the Lithuanian letters and retain their dot when transformed to lowercase.

Some characters exist in two formats: normal width and a full-width, with different Unicode code points. The full-width version is used to mix them smoothly with Asian ideographic characters.

The Japanese half-width katakana was used to represent katakana in 8-bit character codes. Unlike regular (full-width) katakana characters, a letter with dakuten (voiced sound mark) is represented as two code points, the body of letter and dakuten. The combines these into a single code point when converting these characters into full-width.

The CSS text-transform Property

The CSS text-transform property is the key to managing text uppercase and lowercase rendering. There are 5 different values you can use:

  1. lowercase: makes all of the letters in the selected text lowercase
  2. uppercase: makes all of the letters in the selected text uppercase or ALL CAPS
  3. capitalize: capitalizes the first letter of each word in the selected text
  4. none: leaves the text’s case and capitalization exactly as it was entered
  5. inherit: gives the text the case and capitalization of its parent
  6. full-width: Is a keyword forcing the writing of a character (mainly ideograms and latin scripts) inside a square, allowing them to be aligned in the usual East Asian scripts

CSS lowercase

Using the lowercase value forces the text or font to be rendered using lowercase characters.

THIS IS A SCREAMING SENTANCE THAT CAN BE SOFTENED USING LOWERCASE!


transform: lowercase

CSS uppercase — How to Capitalize All Letters in Word

Using the uppercase value forces the text or font to be rendered using uppercase characters.

this example converts an all lowercase string to screaming uppercase.


transform : uppercase

What Is CSS Text-Transform?

You will use the CSS text-transform property if you have some text in an HTML element and want to capitalize it. Essentially, text-transform in CSS gives you the capability to convert any text to:

Lower case

Upper case

Title case

What Is the Syntax for Text-Transform? 

Typically, you will need to define the HTML object where the text you want to transform lives. You will then type curly braces. Inside these curly braces is where you will place the text-transform property.

For instance, if we were to capitalize text in an HTML paragraph, the syntax would be:

As you can see, the styling has two parts separated by a full colon. The left side represents the property, while the right portion is the value. It is also worthwhile to note that you should conclude the line of code with a semicolon.

As a property, text-transform accepts the following values.

None: This property ensures that your text does not transform into any capitalization. You can use it to retain the original case of your text.

Lowercase: Transforms all text characters into lowercase.

Capitalize: This value transforms the first letter of each word in the text selection or objects to uppercase.

Uppercase: All characters in the text will be uppercase. It can be especially useful in writing catchy headings.

Uses of Text-Transform Property 

Text-transform gives you the ability to transform text through HTML object selection dynamically.

Allows ease of capitalizing proper nouns. By using text-transform, usernames will be displayed as a proper noun.

For blog posts and headers. Adding “capitalize” in text-transform can ensure blog post titles are in title case.

Preventing change of text. You can also pass the value ‘none’ to the text-transform property to prevent your text from manipulation.

Punctuation in sentences and paragraphs such as in blog posts news sites.

More on Text-Transform Values

In CSS, the syntax requires a property followed by a value. You will have to change property and value.

For instance, in our “capitalize” example, you see that the property we need to change is the text-transform. In regards to this property, we indicate that we want the transformation to be “capitalize.” To get a grasp of this, take a look at the following code.

Essentially, properties are the accessible characteristics of the HTML object that you can manipulate. In our example, the object is “p” or paragraph. Since our program hypothetically contains some text, we want this text to remain intact – remain unchanged in terms of text transformation. 

Therefore, to communicate this through code, we use “text-transform: none;” When you compare the code from our first article, you’ll notice we only replaced “capitalize” with “none.”

To understand all the text-transform values, we will divide them into two general categories: Keyword and Global values. Global values include inherit, initial, revert, and unset.

Keyword Values 

CSS text-transform keyword values include:

Keyword Values Explanation Notes
Capitalize Typically, this value converts the first character in each word to uppercase. Other letters or characters remain intact and unchanged. CSS capitalize does not affect any punctuation marks. They are ignored, and the first letter is capitalized.
Uppercase All the characters or letters in a particular selection or HTML object are converted to uppercase with this keyword value. However, marks and punctuation marks are left unchanged and intact.
Lowercase This keyword value is the opposite of text uppercase in CSS. Converts the selected text to lowercase except for numbers and punctuation marks.
None This value prevents the letters’ case from being manipulated instead of other keyword values. If you set your text-transform to none, the case stays intact despite injected changes.
Full-width When you use this keyword as the value for your text-transform, the character’s writing is forced inside a square. Consequently, the characters are aligned. This keyword is mainly used in Latin scripts and ideograms. A good example is the usage of this value in Chinese and Japanese Scripts.
Full-size-kana This value is essential for compensating for legibility issues experienced primarily on ruby. It converts the small-sized kana characters to full-size characters.

Значения¶

capitalize Первый символ каждого слова в предложении будет заглавным. Остальные символы свой вид не меняют. lowercase Все символы текста становятся строчными (нижний регистр). uppercase Все символы текста становятся прописными (верхний регистр). none Не меняет регистр символов. full-width Это ключевое слово, которое заставляет писать символы — в основном идеограммы и латинские буквы — внутри квадрата, что позволяет выравнивать их в обычных восточноазиатских шрифтах (например, китайском или японском). full-size-kana Обычно используемое для текста аннотаций , это ключевое слово преобразует все мелкие символы кана в эквивалентные полноразмерные символы кана, чтобы компенсировать проблемы с читаемостью при небольших размерах шрифта, обычно используемых в ruby.

Применяется ко всем элементам

Examples and Usage

To demonstrate the property, we’ll use the following text to apply different capitalization styles: , , , and .

CSS Styling

These examples show us the different capitalization styles that can be applied. By applying the corresponding class to each paragraph, we can observe the effects of each transformation on the text.

The property can have different behavior across languages and specific use cases. For instance, it might not follow language-specific title casing conventions, and its behavior could vary when applied to characters from non-Latin scripts. Always consider potential language and context issues when using it.

Caveat 1: It’s a Transformation, not a Value Assignment

So this feature ensures that the value you see is smoothly updated to the correct case. However, the underlying value is not actually updated.

This means if you enter , you see displayed, but if you do this:

you actually get . Likewise if you end up posting the value to the server via server post operation you are sending the non-transformed value as well.

To complete this solution we still need to update the actual value, and the easiest way to do that without interrupting the display is to do it when the control loses focus via :

By adding the you are forcing the actual value to the correct case when focus leaves the field. This works fine with upper and lower which are common, but a bit more complicated if you should use …

You could also use the code I showed earlier using or , but then you’re back to dealing with the caret location updates.

Regardless of approach, you probably still need at least a little bit of JavaScript to complete this solution.

Выравнивание текста

Простое выравнивание текста по компонентам с помощью классов выравнивания текста. Для выравнивания влево, вправо и по центру доступны адаптивные классы, которые используют те же контрольные точки ширины окна просмотра, что и система сетки.

Текст с выравниванием по левому краю для всех размеров области просмотра.

Выровненный по центру текст на всех размерах области просмотра.

Текст с выравниванием по правому краю для всех размеров области просмотра.

Текст с выравниванием по левому краю в области просмотра размером SM (маленький) или шире.

Текст с выравниванием по левому краю в области просмотра размером MD (средний) или шире.

Текст с выравниванием по левому краю в области просмотра размером LG (большой) или шире.

Текст с выравниванием по левому краю в области просмотра размером XL (очень большой) или шире.

Обратите внимание, что мы не предоставляем служебные классы для выравнивания текста. Хотя эстетически выровненный по ширине текст может выглядеть более привлекательно, он делает интервалы между словами более случайными и, следовательно, труднее читать.

How To Capitalize the Text

If you have content In the form of text and you want to change its capitalization, you first need to define the HTML object where you have written all of your content. Now targeting that object, you can use the text-transform property. The way of writing the syntax is as follows:

p{text-transform: capitalize;}

Now let’s suppose the content contains titles, headings, body text, and some special characters in the middle of different words. In that case, how can you customize all the content on your page? For that matter, you need to target other portions of your content and apply the text-transform property on each piece differently.

– Transformation of Titles

Titles are significant content factors, and you would want your title to be the center of attraction to your readers. So, you should set the “uppercase” value to the text-transform property for the title as the whole title in uppercase would attract the reader more.

This is what the syntax of this value looks like:

div.title{text-transform: uppercase;}

– Transformation for Headings

If you got a few headings in your content, and you want them to be more prominent than the normal body text, you should go with the “capitalize” value to actually capitalize the first character of each word. This is how your headings will not mix with the normal body text.

Let’s take a look at the syntax of this property’s value:

div.headings{text-transform: capitalize;}

– Transformation for the Body Text

You should not use the text-transform property while working on the standard body text. The property would either make all the characters uppercase, lowercase, or make each first letter capital of each word, and neither suits the body content. Thus, not using the text transformation would be a better idea. If you had used any styling over the body text, you could use the “none” value to give the content a presentable look.

So, if you need to mention any list of acronyms or abbreviations or some type of content that needs to be written only in uppercase or lowercase, this property helps you a lot.

Now, this is its simple syntax encased in that div:

div.abbreviations{text-transform: uppercase;}

Supported text-transform Values

The obvious values available and most likely used ones are:

  • uppercase
  • lowercase
  • capitalize

But there are also:

  • none, revert, initial, inherit
    Standard element level CSS values

  • full-width
    Is a keyword that forces the writing of a character — mainly ideograms and Latin scripts — inside a square, allowing them to be aligned in the usual East Asian scripts (like Chinese or Japanese). — from MDN

  • full-size-kana
    Generally used for annotation text, the keyword converts all small Kana characters to the equivalent full-size Kana, to compensate for legibility issues at the small font sizes typically used in ruby. — from MDN

Honestly, I have no idea what the last one even means

How do You Make Each Word in a String or Text Start With a Capital Letter or Title Case the Text?

Title case is where each word in a sentence or string starts with a capital letter. The capitalize value causes a string to render in title case, or at least each word starts with a capital letter.

If a letter in the formatted text is uppercase it will not lower case the letter to make proper title case.

THis soURCE tExT iS All oVER thE PlaCe With LowER and CAPital LeTTerS. but Every wOrd Starts wITH a Capital lEETTER.

this example is a more proper title case example.


transform : capitalize

Notice how the first paragraph, with a random mix of capital and lower case characters does not lower case all the characters? That’s because capitalize is not title-case.

Right now there is no titlecase value available. Instead you should take care to lower case the source before rendering.

Using a Pseudo Selector to Apply a text-transform to the First Letter

A relatively modern feature available to CSS selectors is the concept of a pseudo selector. You can use the ::first-letter selector to apply a different style to the first character of a string.

This allows you to apply some ‘fancy’ styling if you would like. Think about it as way to create that calligraphy affect where the first letter of a chapter is large and decorative.

In this example the lowercase text-transform is applied to the sentence. Then the ::first-letter selector is used to apply custom styling to the paragraph’s first letter. Specifically the first letter is upper case, larger and has a different font family applied.

THis soURCE tExT iS All oVER thE PlaCe With LowER and CAPital LeTTerS. but THE firST wOrd Starts wITH a laRGe Capital lEETTER. This is a second sentance.


first-letter Selector

Tips and Tricks

  • Applying indiscriminately to content might lead to grammar issues in different languages. It’s better to provide grammar-correct text for each language rather than relying solely on CSS transformations.

  • Text set entirely in uppercase can be difficult for people with cognitive concerns, such as dyslexia, to read. Be mindful of accessibility when using the value for large sections of text.

  • The value will capitalize words inside single or double quotes and the first letter after a hyphen, but it won’t capitalize the first letter after a number.

  • The value only affects the first letters of words and won’t change the case of the rest of the letters in a word.

  • Using can be helpful for formatting text consistently, like capitalizing proper nouns in usernames or ensuring blog post titles are in title case.

  • The value can be used to prevent text from being manipulated by inherited styles.

  • Be cautious when using with non-Latin scripts or languages with case distinctions, as the property may not behave as expected across different browsers.

Syntax

text-transform none;
text-transform capitalize;
text-transform uppercase;
text-transform lowercase;
text-transform full-width;
text-transform full-size-kana;


text-transform inherit;
text-transform initial;
text-transform revert;
text-transform unset;

Is a keyword that converts the first letter of each word to uppercase. Other characters remain unchanged (they retain their original case as written in the element’s text). A letter is defined as a character that is part of Unicode’s Letter or Number general categories ; thus, any punctuation marks or symbols at the beginning of a word are ignored.

Note: Authors should not expect to follow language-specific title casing conventions (such as skipping articles in English).

Note: The keyword was under-specified in CSS 1 and CSS 2.1. This resulted in differences between browsers in the way the first letter was calculated (Firefox considered and as letters, but other browsers did not. Both Webkit and Gecko incorrectly considered letter-based symbols like to be real letters. Internet Explorer 9 was the closest to the CSS 2 definition, but with some weird cases.) By precisely defining the correct behavior, CSS Text Level 3 cleans this mess up. The line in the browser compatibility table contains the version the different engines started to support this now precisely-defined behavior.

Is a keyword that converts all characters to uppercase.

Is a keyword that converts all characters to lowercase.

Is a keyword that prevents the case of all characters from being changed.

Is a keyword that forces the writing of a character — mainly ideograms and Latin scripts — inside a square, allowing them to be aligned in the usual East Asian scripts (like Chinese or Japanese).

Generally used for annotation text, the keyword converts all small Kana characters to the equivalent full-size Kana, to compensate for legibility issues at the small font sizes typically used in ruby.

Is Upper Case Really Required?

The most common use case likely is forcing input text to upper case, as is necessary in the application that the textbox shown above is using.

When my client brought up upper casing various inputs, I was somewhat resistant to adding upper casing to fields at first. After all this is a Web application with a backend API that can easily fix up user input on the server when the data is saved on the backend. After all a server application should make sure the data is valid regardless of what the client sends from the UI.

But after giving this some more thought to the issue, I also realized that not providing upper case input make things ambiguous for users. They’ll ask, Do I have to worry about casing, or not? It’s never obvious and many users will — even if auto-fixed up on the server — spent the extra and now wasted effort of explicitly using upper case, which can be a pain especially on mobile devices.

My main hesitation originally (before finding out about ) was I knew that JS based input solutions to upper casing are clunky and require code hookups to map.

The ‘native’ solution of using however is nearly transparent in behavior, so that’s pretty much a no-brainer to add. After creating the CSS class, it’s a simple matter of adding the new style to the class list of the controls in question. Easy peasy.

So auto-casing has definitely its benefits especially if it’s as simple as a CSS style.

# Font Stacks

The browser will attempt to apply the font face «Segoe UI» to the characters within the elements targeted by the above property. If this font is not available, or the font does not contain a glyph for the required character, the browser will fall back to Tahoma, and, if necessary, any sans-serif font on the user’s computer. Note that any font names with more than one word such as «Segoe UI» need to have single or double quotes around them.

The browser will attempt to apply the font face «Consolas» to the characters within the elements targeted by the above property. If this font is not available, or the font does not contain a glyph for the required character, the browser will fall back to «Courier New,» and, if necessary, any monospace font on the user’s computer.

Caveat 2: Placeholder Text is also Transformed

There’s one caveat with that I see with this functionality: The text in the control is also transformed. If you look closely at the screen capture you can see that although I have:

set in the elements, the value that actually displays is PACK NUMBER:

I have to squint really hard for that to make sense: I guess the idea is that the placeholder is meant to be an example of the data to enter, which then should also be upper case. Uhm Ok, but I could also just provide the in upper case, and decide whether I want it to be upper or not?

The problem here is that many applications these days actually use the placeholder as a label or comment and not necessarily as an example of what the data should look like. The placeholder casing override seems extremely heavy handed and and as a result may limit some use cases where you just can’t have upper case place holder text. Grrr…

Chalk that one up as another of the silly things that W3C HTML design by comittee comes up with.

The workaround for this particular solution is to explicitly style the placeholder:

which gives back proper casing for the placeholder:

Line height

Измените высоту строки с помощью утилит.

Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesentmodo cursus magna, vel scelerisque nisl conctetur et. Nullam id dolor id nibh ultricies Vehicula ut id elit. Cras mattis Concectetur Purus Sit Amet Fermentum.

Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesentmodo cursus magna, vel scelerisque nisl conctetur et. Nullam id dolor id nibh ultricies Vehicula ut id elit. Cras mattis Concectetur Purus Sit Amet Fermentum.

Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesentmodo cursus magna, vel scelerisque nisl conctetur et. Nullam id dolor id nibh ultricies Vehicula ut id elit. Cras mattis Concectetur Purus Sit Amet Fermentum.

Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Cras mattis pannenkoek purus sit amet fermentum. Praesentmodo cursus magna, vel scelerisque nisl conctetur et. Nullam id dolor id nibh ultricies Vehicula ut id elit. Cras mattis Concectetur Purus Sit Amet Fermentum.

Понравилась статья? Поделиться с друзьями:
Setup Pro
Добавить комментарий

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: