Input: I AM A STUDENT
Expected Output: I Am A Student
How can I achieve this using css?
Asked
Active
Viewed 279 times
-5

Mr Lister
- 45,515
- 15
- 108
- 150

Saad Ghojaria
- 41
- 1
- 8
-
2If it's written capitalized within the code you cannot change it with CSS – Temani Afif Jun 24 '18 at 10:40
-
3With CSS, the closest you can come is uppercase the first letter of the sentence. https://codepen.io/anon/pen/aKKPjL Otherwise, you need JavaScript. – Mr Lister Jun 24 '18 at 10:47
-
How the input html looks like? Can you control it? – Mosh Feu Jun 24 '18 at 12:57
-
No I can't control it. Thanks got the answer – Saad Ghojaria Feb 01 '21 at 05:20
2 Answers
4
p {
text-transform: lowercase;
}
p:first-line {
display: block;
text-transform: capitalize;
}
<p>I AM A STUDENT</p>

Anil Suwal Qode
- 110
- 5
1
You can use the text-transform
-property of CSS if the text is lowercase to begin with:
p {
text-transform: capitalize;
}
If the text is already capitalized you unfortunately can only transform it into lowercase. Alternatively you could us the ::first letter
-selector like @Mr Lister suggested and put every word into a span like so:
p {
text-transform: lowercase;
}
span {
display: inline-block;
}
span::first-letter {
text-transform: capitalize;
}
<p> <span>I</span> <span>AM</span> <span>A</span> <span>STUDENT</span> </p>
Other than that you could, of course, do this with JavaScript as discussed in this thread but that should be a last resort.

leonheess
- 16,068
- 14
- 77
- 112