HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
h1 Text-wrapping, hyphenation, emojis and what not
ul.skiplinks
li <a href="#css">Skip to the CSS Used</a>
li <a href="#tests">Skip to the Tests</a>
li <a href="#questions">Skip to the Questions</a>
li <a href="#answers">Skip to the Answers</a>
li <a href="#acknowledgements">Skip to the Acknowledgements</a>
h2#css đ
CSS Used
pre
code
| .test {
| width: 50vw;
| -webkit-hyphens: auto;
| -ms-hyphens: auto;
| hyphens: auto;
| padding: 0.5em;
| outline: 1px solid #666;
| }
h2#tests đ° The Tests
h3 Long emoji strings
.testwrapper#test-emoji-pileofpoo
h4 The đŠ emoji
.test
| đŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠđŠ
p.toggleLang đĻđļ
a(href="#test-emoji-pileofpoo") Set/Remove <code>lang</code> attribute
p.showResults đ
a(href="#test-emoji-pileofpoo") Show/Hide Browser test Results
dl.results
dt Safari 10.0.2 (macOS)
dd The đŠ emoji gets text-wrapped, not hyphenated.
dt Chrome 55 (macOS)
dd The đŠ emoji gets text-wrapped, not hyphenated.
dt Chrome 55 (Win10)
dd The đŠ emoji gets text-wrapped, not hyphenated.
dt Firefox 52.0a2 (macOS)
dd The đŠ emoji gets text-wrapped, not hyphenated.
dt Firefox 50 (Win10)
dd The đŠ emoji gets text-wrapped, not hyphenated.
dt IE11 (Win10)
dd The đŠ emoji does not get text-wrapped, nor hyphenated. The container overflows.
dt Edge12 (Win10)
dd The đŠ emoji does not get text-wrapped, nor hyphenated. The container overflows.
.testwrapper#test-emoji-warningtriangle
h4 The â ī¸ emoji
.test
| â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸â ī¸
p.toggleLang đĻđļ
a(href="#test-emoji-warningtriangle") Set/Remove <code>lang</code> attribute
p.showResults đ
a(href="#test-emoji-warningtriangle") Show/Hide Browser test Results
dl.results
dt Safari 10.0.2 (macOS)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container overflows.
dt Chrome 55 (macOS)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container overflows.
dt Chrome 55 (Win10)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container overflows.
dt Firefox 52.0a2 (macOS)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container stretches.
dt Firefox 50 (Win10)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container stretches.
dt IE11 (Win10)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container overflows.
dt Edge12 (Win10)
dd The â ī¸ emoji does not get text-wrapped, nor hyphenated. The container overflows.
h3 Long <code>\w</code> strings
h4 Mutliple long strings
.testwrapper#test-textstrings-multiple
.test
| abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
p.toggleLang đĻđļ
a(href="#test-textstrings-multiple") Set/Remove <code>lang</code> attribute
p.showResults đ
a(href="#test-textstrings-multiple") Show/Hide Browser test Results
dl.results
dt Safari 10.0.2 (macOS)
dd Multiple long strings get hyphenated <em>(<code>-webkit</code> vendor prefix required though)</em>.
dt Chrome 55 (macOS)
dd Multiple long strings get hyphenated, except for the last long string in the series. When a <code>lang</code> attribute is set, the hyphenation changes.
dt Chrome 55 (Win10)
dd Multiple long strings do not get hyphenated.
dt Firefox 52.0a2 (macOS)
dd Multiple long strings do not get hyphenated by default. Only when a <code>lang</code> attribute is set to <a href="https://developer.mozilla.org/en/docs/Web/CSS/hyphens#Notes_on_supported_languages">one of the supported languages</a> the text is hyphenated.
dt Firefox 50 (Win10)
dd Multiple long strings do not get hyphenated by default. Only when a <code>lang</code> attribute is set to <a href="https://developer.mozilla.org/en/docs/Web/CSS/hyphens#Notes_on_supported_languages">one of the supported languages</a> the text is hyphenated.
dt IE11 (Win10)
dd Multiple long strings do not get hyphenated. The container overflows.
dt Edge12 (Win10)
dd Multiple long strings do not get hyphenated. The container overflows.
.testwrapper#test-textstrings-single
h4 Single long string
.test
| abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
p.toggleLang đĻđļ
a(href="#test-textstrings-single") Set/Remove <code>lang</code> attribute
p.showResults đ
a(href="#test-textstrings-single") Show/Hide Browser test Results
dl.results
dt Safari 10.0.2 (macOS)
dd Single long strings get hyphenated <em>(<code>-webkit</code> vendor prefix required though)</em>
dt Chrome 55 (macOS)
dd A single long string does not get hyphenated <em>(because it is the last one, cfr. multiple long strings â see above)</em>
dt Chrome 55 (Win10)
dd Multiple long strings do not get hyphenated.
dt Firefox 52.0a2 (macOS)
dd Single long strings do not get hyphenated by default. Only when a <code>lang</code> attribute is set to <a href="https://developer.mozilla.org/en/docs/Web/CSS/hyphens#Notes_on_supported_languages">one of the supported languages</a> the text is hyphenated.
dt Firefox 50 (Win10)
dd Single long strings do not get hyphenated by default. Only when a <code>lang</code> attribute is set to <a href="https://developer.mozilla.org/en/docs/Web/CSS/hyphens#Notes_on_supported_languages">one of the supported languages</a> the text is hyphenated.
dt IE11 (Win10)
dd Multiple long strings do not get hyphenated. The container overflows.
dt Edge12 (Win10)
dd Multiple long strings do not get hyphenated. The container overflows.
h2#questions âī¸ Questions
p Looking at the results, this raises some questions
h3 Core questions
ol
li Why do some emojis get text-wrapped, and some not? → <a href="https://www.bram.us/2016/12/23/text-wrapping-hyphenation-emojis-and-what-not/#question_1" target="_top">Answered!</a>
li If the above is a feature: is there a list of emojis â or can we detect which emojis â that get text-wrapped (and those who are not) available somewhere? → <a href="https://www.bram.us/2016/12/23/text-wrapping-hyphenation-emojis-and-what-not/#question_2" target="_top">Answered!</a>
li Why do emojis get text-wrapped, and not hyphenated? → <a href="https://www.bram.us/2016/12/23/text-wrapping-hyphenation-emojis-and-what-not/#question_3" target="_top">Answered!</a>
h3 Browser specific Questions
ol(start=4)
li Why, in Chrome 55, is hyphenation not applied on the last string? → <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=676890&can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=">It's a bug. <del>Fixed in Chrome 56 and up</del>.</a> <ins>This issue regressed, and is now properly fixed in Chrome 90</ins>
li Why, in Firefox 52.0a2, does the container stretch out on the â ī¸-test, whilst other browsers overflow?
li Why, in IE11/Edge12, does the đŠ-test not wrap, whilst other browsers do?
li Why, in IE11/Edge12, does hyphenation not work <a href="http://caniuse.com/#feat=css-hyphens" target="_top">even though it should</a>? Setting the <code>lang</code> to <code>en-US</code>, or setting the <code>lang</code> on the <code>body</code> or <code>html</code> yield the same result.
li Why, in Chrome 55 and Safari 10.0.2, is hyphenation applied even when the required <code>lang</code> is not set?
h2#answers âšī¸ Answers
p Thanks to <a href="https://twitter.com/KhaledGhetas">Khaled Hosny</a> I've been able to crack this nut and answer the core questions. <a href="https://www.bram.us/2016/12/23/text-wrapping-hyphenation-emojis-and-what-not/" target="_top">Check out the answers on my blog</a>.
h2#acknowledgements đ Acknowledgements
p Thanks go out to to:
ul
li <a href="https://twitter.com/haroenv">Haroen Viaene</a> for providing test results data on Win10.
li <a href="https://twitter.com/KhaledGhetas">Khaled Hosny</a> for <a href="https://twitter.com/KhaledGhetas/status/812311551474536448">pointing</a> me towards the needed Line Breaking Properties Specification to solving this.
html, body
margin 0
padding 0
*
box-sizing border-box
html, body
width 100vw
height 100vh
body
padding 1vw
font-size calc(1em + 0.2vw)
del, ins
font-style: italic;
ul.skiplinks
margin 0
padding 0
li
margin 0
padding 0
list-style-type none
&:before
content 'â '
@keyframes yellowfade {
0% { background-color: yellow; }
100% { background-color: transparent; }
}
h2
margin-top 10vw
&:target
background-color yellow
animation yellowfade 500ms ease-in-out 1000ms 1 forwards
h3
margin-top 5vw
.test
width 50vw
-webkit-hyphens auto
-ms-hyphens auto
hyphens auto
padding 0.5em
outline 1px solid #666
margin 2em 0 1em
position relative
&::before
content 'NO LANG ATTR SET'
position absolute
top 0
left -1px
background dimgray
color #fff
font-size 0.8em
line-height 0.8em
padding 0.4em 0.6em
font-family Consolas, Courier New, monospace
transform translate3d(0,-100%,0)
opacity 0.4
&[lang="en"]::before
content 'lang="en"'
background darkgreen
opacity 1
.setLanguage:before
content 'đ '
dl.results
width calc(50vw - 0.5em)
display flex
flex-direction row
flex-wrap wrap
align-items baseline
margin 1em 0 1em 1.5em
display none
&--visible
display flex
dt
flex 0 1 12.5vw
font-style italic
margin 0
padding 0.5em 0 0 0
dd
flex 0 1 calc(37.5vw - 0.5em)
margin 0
padding 0.5em 0 0 0.5em
&:before
content 'â '
document.addEventListener('DOMContentLoaded', (e) => {
Array.from(document.querySelectorAll('.toggleLang a')).forEach(($el) => {
$el.addEventListener('click', (e) => {
e.preventDefault();
const target = document.querySelector(`${e.currentTarget.getAttribute('href')} .test`);
if (target.getAttribute('lang')) {
target.removeAttribute('lang');
} else {
target.setAttribute('lang', 'en');
}
});
});
Array.from(document.querySelectorAll('.showResults a')).forEach(($el) => {
$el.addEventListener('click', (e) => {
e.preventDefault();
const target = document.querySelector(`${e.currentTarget.getAttribute('href')} .results`);
target.classList.toggle('results--visible');
});
});
});
Also see: Tab Triggers