Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="language-select-wrapper">
    <select class="language-select" id="language">
        <option value="ja">日本語</option>
        <option value="en">English</option>
        <option value="ko">한국어</option>
    </select>
</div>

<p data-lang-key="lead01">こんにちは、世界!</p>
<p data-lang-key="lead02">私たちのウェブサイトへようこそ。</p>
<a href="contact.html" data-lang-key="contact">お問い合わせ</a>
              
            
!

CSS

              
                body {
    padding: 20px;
}

.language-select-wrapper {
    width: 200px;
    position: relative;
}

.language-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 10px;
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: white;
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048"><path d="M0 0h2048L1024 1024z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px 12px;
    cursor: pointer;
}

.language-select:focus {
    outline: none;
    border-color: #007bff;
}

.language-select:hover {
    border-color: #007bff;
}
              
            
!

JS

              
                // 言語データの準備
const languageData = {
    'en': {
        'lead01': 'Hello, World!',
        'lead02': 'Welcome to our website.',
        'contact': 'Contact us'
    },
    'ja': {
        'lead01': 'こんにちは、世界!',
        'lead02': '私たちのウェブサイトへようこそ。',
        'contact': 'お問い合わせ'
    },
    'ko': {
        'lead01': '안녕하세요, 세계!',
        'lead02': '우리 웹사이트에 오신 것을 환영합니다.',
        'contact': '문의하기'
    }
};

// セレクトボックスのchangeイベント設定
const langs =  document.getElementById('language');
langs.addEventListener('change', (e) => {
    changeLanguage(e.target.value);
});

// changeイベントで実行する関数
// セレクトボックスから渡された値と言語データのキーを元に
// それぞれのHTMLタグに翻訳したテキストを設定する。
const changeLanguage = function(lang) {
    let elements = document.querySelectorAll('[data-lang-key]');
    elements.forEach(function (element) {
        let key = element.getAttribute('data-lang-key');
        let text = languageData[lang][key];
        element.textContent = text;
    });
}
              
            
!
999px

Console