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.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>addr verification sample</title>
</head>
<body>
<h3>住所入力</h3>
<p>
<input id="anormInput" placeholder="住所を入力してください" value="東京都文京区本駒込2丁目28-10 文京グリーンコート" type="text">
<button id="submitButton">住所確認APIを実行</button>
</p>
<hr>
<h3>住所確認API結果</h3>
<p>APIレスポンスコード:<span id="status"></span><br>
<span id="errorMessage"></span>
</p>
<table border="1">
<tr>
<th>フィールド名</th>
<th>正規化結果</th>
</tr>
<tr>
<td>入力住所文字列</td>
<td id="query"></td>
</tr>
<tr>
<td>正規化後の住所文字列</td>
<td id="placeName"></td>
</tr>
<tr>
<td>都道府県名</td>
<td id="pref"></td>
</tr>
<tr>
<td>都道府県読み</td>
<td id="prefKana"></td>
</tr>
<tr>
<td>市区町村名</td>
<td id="city"></td>
</tr>
<tr>
<td>市区町村読み</td>
<td id="cityKana"></td>
</tr>
<tr>
<td>町域名</td>
<td id="area"></td>
</tr>
<tr>
<td>町域名読み</td>
<td id="areaKana"></td>
</tr>
<tr>
<td>小字・丁目</td>
<td id="koazaChome"></td>
</tr>
<tr>
<td>小字・丁目読み</td>
<td id="koazaChomeKana"></td>
</tr>
<tr>
<td>番地・号</td>
<td id="banchiGo"></td>
</tr>
<tr>
<td>建物名称部</td>
<td id="building"></td>
</tr>
<tr>
<td>建物数字部</td>
<td id="buildingNumber"></td>
</tr>
<tr>
<td>郵便番号</td>
<td id="zipcode"></td>
</tr>
<tr>
<td>解析レベル</td>
<td id="geocodingLevel"></td>
</tr>
<tr>
<td>解析レベル説明</td>
<td id="geocodingLevelDesc"></td>
</tr>
<tr>
<td>解析ログメッセージ</td>
<td id="log"></td>
</tr>
<tr>
<td>正規化できなかった文字列</td>
<td id="notNormalized"></td>
</tr>
</table>
<h3>ジオコーディング結果</h3>
<p>
<table border="1">
<tr>
<th>フィールド名</th>
<th>ジオコーディング結果</th>
</tr>
<tr>
<td>経度,緯度</td>
<td id="coordinates"></td>
</tr>
</table>
<span id="geocodingMessage">
※ジオコーディングサービスをご契約のお客様のみご利用いただけます<br>
ジオコーディングを試したい場合はJavaScriptのURI末尾を修正してください
</span>
</p>
<footer>GeoTechnologies Addr Verification API Sample Code</footer>
</body>
</html>
body {
text-align: center;
}
table {
border-collapse: collapse;
margin: auto;
text-align: left;
}
#errorMessage {
font-size: 12px;
color: red;
}
#anormInput {
width: 75%;
max-width: 450px;
}
#geocodingMessage {
color: red;
}
/**
* ボタン押下時に住所確認APIを実行します
*/
document.getElementById("submitButton").onclick = function () {
// 住所確認APIにリクエストを送信します
fetch(makeURI(), {
// YourApiKey部分をお客様のAPIキーに修正してください
// 例 "x-api-key": "6QHCWbbsnQ1K08IcwP",
headers: { "x-api-key": "YourApiKey", accept: "application/json" }
})
.then((response) => {
// 住所確認APIのレスポンスコードを解析します
analyzeResponseCode(response.status);
return response.json();
})
.then((result) => {
// 住所正規化結果を解析して表示します
getNormalized(result);
})
.catch((error) => {
// エラー時の処理を記載します
// alert(error);
});
};
/**
* 住所確認API用のURIを作成します
* @return {string} 住所確認API用のURI
*/
function makeURI() {
const urlValue =
"https://api-anorm.mapfan.com/v1/" +
document.getElementById("anormInput").value +
// ジオコーディング機能をお試しの場合は「.geojson」を使用してください
// ジオコーディングサービスをご契約のお客様のみご利用いただけます
".json";
return encodeURI(urlValue);
}
/**
* 住所確認APIのレスポンスコードを解析し、表示・エラー出力を行います
* @param {string} responseCode 住所確認APIのレスポンスコード
*/
function analyzeResponseCode(responseCode) {
document.getElementById("status").innerHTML = responseCode;
// 200以外のレスポンスコードはエラーです
if (responseCode == "200")
document.getElementById("errorMessage").innerHTML = "";
else if (responseCode == "400")
document.getElementById("errorMessage").innerHTML =
"住所入力が行われているか確認してください";
else if (responseCode == "403")
document.getElementById("errorMessage").innerHTML =
"JavaScriptのAPIキーが正しいか確認してください";
else
document.getElementById("errorMessage").innerHTML =
"システムエラーが発生しました";
}
/**
* 住所正規化結果を解析し表示します
* @param {json} result 住所確認APIの住所正規化結果
*/
function getNormalized(result) {
// 一件目の住所正規化結果を取得します
// 複数件リクエストした場合は複数件取得する処理に変更します
const feature = result.features[0];
// 入力住所文字列
document.getElementById("query").innerHTML = feature.properties.query;
// 正規化後の住所文字列
document.getElementById("placeName").innerHTML =
feature.properties.place_name;
// 都道府県名
document.getElementById("pref").innerHTML = feature.properties.pref;
// 都道府県読み
document.getElementById("prefKana").innerHTML = feature.properties.pref_kana;
// 市区町村名
document.getElementById("city").innerHTML = feature.properties.city;
// 市区町村読み
document.getElementById("cityKana").innerHTML = feature.properties.city_kana;
// 町域名
document.getElementById("area").innerHTML = feature.properties.area;
// 町域名読み
document.getElementById("areaKana").innerHTML = feature.properties.area_kana;
// 小字・丁目
document.getElementById("koazaChome").innerHTML =
feature.properties.koaza_chome;
// 小字・丁目読み
document.getElementById("koazaChomeKana").innerHTML =
feature.properties.koaza_chome_kana;
// 番地・号
document.getElementById("banchiGo").innerHTML = feature.properties.banchi_go;
// 建物名称部
document.getElementById("building").innerHTML = feature.properties.building;
// 建物数字部
document.getElementById("buildingNumber").innerHTML =
feature.properties.building_number;
// 郵便番号
document.getElementById("zipcode").innerHTML = feature.properties.zipcode;
// 解析レベル
document.getElementById("geocodingLevel").innerHTML =
feature.properties.geocoding_level;
// 解析レベル説明
document.getElementById("geocodingLevelDesc").innerHTML =
feature.properties.geocoding_level_desc;
// 解析ログメッセージ
document.getElementById("log").innerHTML = feature.properties.log;
// 正規化できなかった文字列
document.getElementById("notNormalized").innerHTML =
feature.properties.not_normalized;
// 経度,緯度
document.getElementById("coordinates").innerHTML =
feature.geometry.coordinates;
}
Also see: Tab Triggers