CINXE.COM
Sortable | jQuery UI
<!doctype html> <html class="no-js" lang="en-US"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Sortable | jQuery UI</title> <meta name="author" content="OpenJS Foundation - openjsf.org"> <meta name="description" content="jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice."> <meta name="viewport" content="width=device-width"> <link rel="shortcut icon" href="https://jqueryui.com/wp-content/themes/jqueryui.com/i/favicon.ico"> <link rel="stylesheet" href="https://jqueryui.com/wp-content/themes/jquery/lib/typesense-minibar/typesense-minibar.css?v=c5fa9b9a"> <link rel="stylesheet" href="https://jqueryui.com/wp-content/themes/jquery/css/base.css?v=9fa813cf"> <link rel="stylesheet" href="https://jqueryui.com/wp-content/themes/jqueryui.com/style.css?v=7a640af9"> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <script src="https://jqueryui.com/wp-content/themes/jquery/js/main.js?v=10baaffd"></script> <script defer type="module" src="https://jqueryui.com/wp-content/themes/jquery/lib/typesense-minibar/typesense-minibar.js?v=830f1ee1"></script> <meta name='robots' content='max-image-preview:large' /> <style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style> <link rel="https://api.w.org/" href="https://jqueryui.com/wp-json/" /><link rel="alternate" title="JSON" type="application/json" href="https://jqueryui.com/wp-json/wp/v2/pages/64" /><meta name="generator" content="WordPress 6.7.1" /> <link rel="canonical" href="https://jqueryui.com/sortable/" /> <link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="https://jqueryui.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fjqueryui.com%2Fsortable%2F" /> <link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="https://jqueryui.com/wp-json/oembed/1.0/embed?url=https%3A%2F%2Fjqueryui.com%2Fsortable%2F&format=xml" /> </head> <body class="jquery-ui page-template-default page page-id-64 page-slug-sortable single-author singular"> <header> <section id="global-nav"> <nav> <div class="constrain"> <ul class="projects"> <li class="project jquery"><a href="https://jquery.com/" title="jQuery">jQuery</a></li> <li class="project jquery-ui"><a href="https://jqueryui.com/" title="jQuery UI">jQuery UI</a></li> <li class="project jquery-mobile"><a href="https://jquerymobile.com/" title="jQuery Mobile">jQuery Mobile</a></li> <li class="project sizzlejs"><a href="https://sizzlejs.com/" title="Sizzle">Sizzle</a></li> <li class="project qunitjs"><a href="https://qunitjs.com/" title="QUnit">QUnit</a></li> </ul> <ul class="links"> <li><a href="https://plugins.jquery.com/">Plugins</a></li> <li class="dropdown"><a href="https://contribute.jquery.org/">Contribute</a> <ul> <li><a href="https://cla.openjsf.org/">CLA</a></li> <li><a href="https://contribute.jquery.org/style-guide/">Style Guides</a></li> <li><a href="https://contribute.jquery.org/triage/">Bug Triage</a></li> <li><a href="https://contribute.jquery.org/code/">Code</a></li> <li><a href="https://contribute.jquery.org/documentation/">Documentation</a></li> <li><a href="https://contribute.jquery.org/web-sites/">Web Sites</a></li> </ul> </li> <li class="dropdown"><a href="https://events.jquery.org/">Events</a> <ul class="wide"> </ul> </li> <li class="dropdown"><a href="https://jquery.com/support/">Support</a> <ul> <li><a href="https://learn.jquery.com/">Learning Center</a></li> <li><a href="https://jquery.com/support/">Chat</a></li> <li><a href="https://stackoverflow.com/tags/jquery/info">Stack Overflow</a></li> <li><a href="https://contribute.jquery.org/bug-reports/">Report a bug</a></li> </ul> </li> <li class="dropdown"><a href="https://openjsf.org/">OpenJS Foundation</a> <ul> <li><a href="https://openjsf.org/join">Join</a></li> <li><a href="https://openjsf.org/members">Members</a></li> <li><a href="https://jquery.com/team">jQuery Team</a></li> <li><a href="https://openjsf.org/governance">Governance</a></li> <li><a href="https://code-of-conduct.openjsf.org/">Conduct</a></li> <li><a href="https://openjsf.org/projects">Projects</a></li> </ul> </li> </ul> </div> </nav> </section> </header> <div id="container"> <div id="logo-events" class="constrain clearfix"> <h2 class="logo"><a href="/" title="jQuery UI">jQuery UI</a></h2> <aside id="broadcast"></aside> </div> <nav id="main" class="constrain clearfix"> <div class="menu-top-container"> <button hidden id="menu-trigger" class="button menu-trigger" aria-expanded="false" aria-haspopup="menu">Navigation</button> <ul id="menu-top" class="menu" role="menu" aria-labelledby="menu-trigger"> <li class="menu-item"><a href="https://jqueryui.com/demos/">Demos</a></li> <li class="menu-item"><a href="https://jqueryui.com/download/">Download</a></li> <li class="menu-item"><a href="https://api.jqueryui.com/">API Documentation</a></li> <li class="menu-item"><a href="https://jqueryui.com/themeroller/">Themes</a></li> <li class="menu-item"><a href="https://jqueryui.com/development/">Development</a></li> <li class="menu-item"><a href="https://jqueryui.com/support/">Support</a></li> <li class="menu-item"><a href="https://blog.jqueryui.com/">Blog</a></li> <li class="menu-item"><a href="https://jqueryui.com/about/">About</a></li> </ul> </div> <typesense-minibar data-origin="https://typesense.jquery.com" data-collection="jqueryui_com" data-key="Zh8mMgohXECel9wjPwqT7lekLSG3OCgz" data-foot="true" data-group="true" > <form role="search" class="searchform" action="https://jqueryui.com/" method="get"> <input type="search" name="s" aria-label="Search jQuery UI" value="" placeholder="Search" autocomplete="off"> <button type="submit" class="visuallyhidden"></button> </form> </typesense-minibar> </nav> <div id="content-wrapper" class="clearfix row"> <div class="content-right twelve columns"> <div id="content"> <h1 class="entry-title">Sortable</h1> <hr> <p class="desc">Reorder elements in a list or grid using the mouse.</p> <div class="demo-list"><h2>Examples</h2><ul><li class="active"><a href="/resources/demos/sortable/default.html">Default functionality</a></li><li><a href="/resources/demos/sortable/connect-lists.html">Connect lists</a></li><li><a href="/resources/demos/sortable/display-grid.html">Display as grid</a></li><li><a href="/resources/demos/sortable/placeholder.html">Drop placeholder</a></li><li><a href="/resources/demos/sortable/empty-lists.html">Handle empty lists</a></li><li><a href="/resources/demos/sortable/items.html">Include / exclude items</a></li><li><a href="/resources/demos/sortable/portlets.html">Portlets</a></li></ul></div><iframe src="/resources/demos/sortable/default.html" class="demo-frame"></iframe><div class="demo-description"> <p> Enable a group of DOM elements to be sortable. Click on and drag an element to a new spot within the list, and the other items will adjust to fit. By default, sortable items share <code>draggable</code> properties. </p> </div><div class="view-source"><a tabindex="0"><i class="icon-eye-open"></i> view source</a><div><div class="syntaxhighlighter xml"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> <div class="line n7">7</div> <div class="line n8">8</div> <div class="line n9">9</div> <div class="line n10">10</div> <div class="line n11">11</div> <div class="line n12">12</div> <div class="line n13">13</div> <div class="line n14">14</div> <div class="line n15">15</div> <div class="line n16">16</div> <div class="line n17">17</div> <div class="line n18">18</div> <div class="line n19">19</div> <div class="line n20">20</div> <div class="line n21">21</div> <div class="line n22">22</div> <div class="line n23">23</div> <div class="line n24">24</div> <div class="line n25">25</div> <div class="line n26">26</div> <div class="line n27">27</div> <div class="line n28">28</div> <div class="line n29">29</div> <div class="line n30">30</div> <div class="line n31">31</div> <div class="line n32">32</div> <div class="line n33">33</div> <div class="line n34">34</div> <div class="line n35">35</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="hljs-meta"><!DOCTYPE <span class="hljs-meta-keyword">html</span>></span><span class="hljs-tag"><<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>></span><span class="hljs-tag"><<span class="hljs-name">head</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1"</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">title</span>></span>jQuery UI Sortable - Default functionality<span class="hljs-tag"></<span class="hljs-name">title</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://code.jquery.com/ui/1.14.1/themes/base/jquery-ui.css"</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/resources/demos/style.css"</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">style</span>></span><span class="css"></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-selector-id">#sortable</span> { <span class="hljs-attribute">list-style-type</span>: none; <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>; <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>; <span class="hljs-attribute">width</span>: <span class="hljs-number">60%</span>; }</code></div></div><div class="container"><div class="line"><code> <span class="hljs-selector-id">#sortable</span> <span class="hljs-selector-tag">li</span> { <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">3px</span> <span class="hljs-number">3px</span> <span class="hljs-number">3px</span>; <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.4em</span>; <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">1.5em</span>; <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.4em</span>; <span class="hljs-attribute">height</span>: <span class="hljs-number">18px</span>; }</code></div></div><div class="container"><div class="line"><code> <span class="hljs-selector-id">#sortable</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">span</span> { <span class="hljs-attribute">position</span>: absolute; <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">1.3em</span>; }</code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"></<span class="hljs-name">style</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://code.jquery.com/jquery-3.7.1.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://code.jquery.com/ui/1.14.1/jquery-ui.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"></span></code></div></div><div class="container"><div class="line"><code> $( <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{</code></div></div><div class="container"><div class="line"><code> $( <span class="hljs-string">"#sortable"</span> ).sortable();</code></div></div><div class="container"><div class="line"><code> } );</code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></div></div><div class="container"><div class="line"><code><span class="hljs-tag"></<span class="hljs-name">head</span>></span></code></div></div><div class="container"><div class="line"><code><span class="hljs-tag"><<span class="hljs-name">body</span>></span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="hljs-tag"><<span class="hljs-name">ul</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sortable"</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 1<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 2<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 3<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 4<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 5<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 6<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code> <span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-state-default"</span>></span><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ui-icon ui-icon-arrowthick-2-n-s"</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>Item 7<span class="hljs-tag"></<span class="hljs-name">li</span>></span></code></div></div><div class="container"><div class="line"><code><span class="hljs-tag"></<span class="hljs-name">ul</span>></span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="hljs-tag"></<span class="hljs-name">body</span>></span><span class="hljs-tag"></<span class="hljs-name">html</span>></span></code></div></div></pre> </td> </tr> </tbody> </table> </div> </div></div> <p>Want to learn more about the sortable interaction? Check out the <a href="https://api.jqueryui.com/sortable/">API documentation</a>.</p> </div> <div id="sidebar" class="widget-area" role="complementary"> <aside class="widget"> <h3 class="widget-title">Interactions</h3> <ul> <li><a href="https://jqueryui.com/draggable/">Draggable</a></li><li><a href="https://jqueryui.com/droppable/">Droppable</a></li><li><a href="https://jqueryui.com/resizable/">Resizable</a></li><li><a href="https://jqueryui.com/selectable/">Selectable</a></li><li><a href="https://jqueryui.com/sortable/">Sortable</a></li> </ul> </aside> <aside class="widget"> <h3 class="widget-title">Widgets</h3> <ul> <li><a href="https://jqueryui.com/accordion/">Accordion</a></li><li><a href="https://jqueryui.com/autocomplete/">Autocomplete</a></li><li><a href="https://jqueryui.com/button/">Button</a></li><li><a href="https://jqueryui.com/checkboxradio/">Checkboxradio</a></li><li><a href="https://jqueryui.com/controlgroup/">Controlgroup</a></li><li><a href="https://jqueryui.com/datepicker/">Datepicker</a></li><li><a href="https://jqueryui.com/dialog/">Dialog</a></li><li><a href="https://jqueryui.com/menu/">Menu</a></li><li><a href="https://jqueryui.com/progressbar/">Progressbar</a></li><li><a href="https://jqueryui.com/selectmenu/">Selectmenu</a></li><li><a href="https://jqueryui.com/slider/">Slider</a></li><li><a href="https://jqueryui.com/spinner/">Spinner</a></li><li><a href="https://jqueryui.com/tabs/">Tabs</a></li><li><a href="https://jqueryui.com/tooltip/">Tooltip</a></li> </ul> </aside> <aside class="widget"> <h3 class="widget-title">Effects</h3> <ul> <li><a href="https://jqueryui.com/addClass/">Add Class</a></li><li><a href="https://jqueryui.com/animate/">Color Animation</a></li><li><a href="https://jqueryui.com/easing/">Easing</a></li><li><a href="https://jqueryui.com/effect/">Effect</a></li><li><a href="https://jqueryui.com/hide/">Hide</a></li><li><a href="https://jqueryui.com/removeClass/">Remove Class</a></li><li><a href="https://jqueryui.com/show/">Show</a></li><li><a href="https://jqueryui.com/switchClass/">Switch Class</a></li><li><a href="https://jqueryui.com/toggle/">Toggle</a></li><li><a href="https://jqueryui.com/toggleClass/">Toggle Class</a></li> </ul> </aside> <aside class="widget"> <h3 class="widget-title">Utilities</h3> <ul> <li><a href="https://jqueryui.com/position/">Position</a></li><li><a href="https://jqueryui.com/widget/">Widget Factory</a></li> </ul> </aside> </div> </div> </div> </div> <footer class="clearfix simple"> <div class="constrain"> <div class="row"> <div class="six columns centered"> <h3><span>Books</span></h3> <ul class="books"> <li> <a href="https://www.manning.com/books/jquery-ui-in-action"> <span><img src="https://jqueryui.com/wp-content/themes/jquery/content/books/jquery-ui-in-action.jpg" alt="jQuery UI in Action by TJ VanToll" width="92" height="114"></span> <strong>jQuery UI in Action</strong><br> <cite>TJ VanToll</cite> </a> </li> <li> <a href="https://www.packtpub.com/web-development/jquery-ui-themes-beginners-guide"> <img src="https://jqueryui.com/wp-content/themes/jquery/content/books/jquery-ui-themes.jpg" alt="jQuery UI Themes by Adam Boduch" width="92" height="114"> <span class="book-title">jQuery UI Themes</span> <cite>Adam Boduch</cite> </a> </li> <li> <a href="https://www.packtpub.com/web-development/jquery-ui-cookbook"> <img src="https://jqueryui.com/wp-content/themes/jquery/content/books/jquery-ui-cookbook.jpg" alt="jQuery UI Cookbook by Adam Boduch" width="92" height="114"> <span class="book-title">jQuery UI Cookbook</span> <cite>Adam Boduch</cite> </a> </li> </ul> </div> </div> <div id="legal" class="legal"> <ul class="footer-site-links"> <li><a class="icon-pencil" href="https://learn.jquery.com/">Learning Center</a></li> <li><a class="icon-comments" href="https://jquery.com/support/">Chat</a></li> <li><a class="icon-twitter" href="https://twitter.com/jqueryui">Twitter</a></li> <li><a class="icon-github" href="https://github.com/jquery">GitHub</a></li> </ul> <p class="copyright"> Copyright 2024 <a href="https://openjsf.org/">OpenJS Foundation</a> and jQuery contributors. All rights reserved. See <a href="https://jquery.com/license/">jQuery License</a> for more information. The <a href="https://openjsf.org/">OpenJS Foundation</a> has registered trademarks and uses trademarks. For a list of trademarks of the <a href="https://openjsf.org/">OpenJS Foundation</a>, please see our <a href="https://trademark-policy.openjsf.org/">Trademark Policy</a> and <a href="https://trademark-list.openjsf.org/">Trademark List</a>. Trademarks and logos not indicated on the <a href="https://trademark-list.openjsf.org/">list of OpenJS Foundation trademarks</a> are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. OpenJS Foundation <a href="https://terms-of-use.openjsf.org/">Terms of Use</a>, <a href="https://privacy-policy.openjsf.org/">Privacy</a>, and <a href="https://www.linuxfoundation.org/cookies">Cookie</a> Policies also apply. </p> <p><a href="https://www.digitalocean.com" class="do-link">Web hosting by Digital Ocean</a> | <a href="https://www.fastly.com/">CDN by Fastly</a> | <a href="https://wordpress.org/" class="wp-link">Powered by WordPress</a></p> </div> </div> </footer> </body> </html>