{"id":357,"date":"2024-01-05T19:27:39","date_gmt":"2024-01-05T19:27:39","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=357"},"modified":"2024-01-05T19:28:28","modified_gmt":"2024-01-05T19:28:28","slug":"auto-sizing-textarea","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/auto-sizing-textarea\/","title":{"rendered":"Auto-Sizing Textarea"},"content":{"rendered":"\n<p>Credit to Stephen Shaw for the original idea, there is a decently easy way to make an auto-sizing <code>&lt;textarea&gt;<\/code> element. <a href=\"https:\/\/codepen.io\/chriscoyier\/pen\/XWKEVLy\">It is here.<\/a> But it&#8217;s not perfect. There is a frustrating hard-to-replicate <a href=\"https:\/\/til.simonwillison.net\/css\/resizing-textarea#user-content-the-mobile-safari-bug\">iOS bug<\/a>. Plus it&#8217;s just a trick. It requires JavaScript and some pretty specific CSS to pull off. <\/p>\n\n\n\n<p>It&#8217;s awesome to see the web platform <a href=\"https:\/\/groups.google.com\/a\/chromium.org\/g\/blink-dev\/c\/MjCCRQo9Qk0\/m\/XTjOSVDcAAAJ\">pick up<\/a> an easy one-liner way to do this, by way of a new CSS property:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">textarea<\/span> {\n  <span class=\"hljs-attribute\">field-sizing<\/span>: content;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<!--more-->\n\n\n\n<p>Adam Argyle <a href=\"https:\/\/codepen.io\/argyleink\/pen\/JjxQLoW\">has a simple demo here<\/a> to play with (<em>note how the <code>field-sizing<\/code> can apply to <code>inline<\/code> size as well as <code>block<\/code> size<\/em>). As I write, Chrome Canary has it in v122, and should go out in stable in late February. Let&#8217;s \ud83d\ude4f for quick cross-browser support. <\/p>\n\n\n\n<p>At one time when this was being played with, the CSS property was called <code>form-sizing<\/code>, but I think I like the update to <code>field-sizing<\/code>. I think of these things as &#8220;fields&#8221;, and quite notably it works on <code>&lt;input&gt;<\/code> as well as <code>&lt;textarea&gt;<\/code>. Fork Adam&#8217;s demo and have it apply to an input instead to see it work (in Chrome Canary). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Credit to Stephen Shaw for the original idea, there is a decently easy way to make an auto-sizing &lt;textarea&gt; element. It is here. But it&#8217;s not perfect. There is a frustrating hard-to-replicate iOS bug. Plus it&#8217;s just a trick. It requires JavaScript and some pretty specific CSS to pull off. It&#8217;s awesome to see the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":359,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[7,59,31],"class_list":["post-357","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-css","tag-forms","tag-html"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/auto-grow-textarea-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":3,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions\/361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/359"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}