Description

This example shows you how to change the position of the labels relative to the respective input elements. The labels can be positioned on the 'left', 'right', 'top' or 'bottom' of the input element. To change the label position, set the labelPosition property to the desired value. The default position is on the left side of the input element.

jQuery Form: Form Input Label Position

jQuery Form Input Elements and Labels Positioning.

A live JavaScript/jQuery example of jqxForm, the jQWidgets Form component, with its complete source code below. It is one of 7 jqxForm demos for jQuery.

jqxForm API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxForm shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxinput.js, jqxlistbox.js, jqxscrollbar.js, jqxpanel.js, jqxdropdownlist.js, jqxform.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var theme = $.data(document.body, 'theme');
    if (theme == null || theme == undefined)
        theme = 'classic';

    var template = [
        {
            bind: 'item1',
            type: 'text',
            label: 'Label position left',
            labelPosition: 'left',
            align: 'left',
            width: '200px',
            required: true
        },
        {
            bind: 'item2',
            type: 'text',
            label: 'Label position right',
            labelPosition: 'right',
            align: 'left',
            width: '200px',
            required: true,
            requiredPosition: 'left'
        },
        {
            bind: 'item3',
            type: 'text',
            label: 'Label position top',
            labelPosition: 'top',
            align: 'left',
            width: '200px',
            required: true
        },
        {
            bind: 'item4',
            type: 'text',
            label: 'Label position bottom',
            labelPosition: 'bottom',
            labelAlign: 'left',
            width: '200px',
            required: true
        }
    ];

    $('#sampleForm').jqxForm({
        template: template,
        padding: { left: 10, top: 10, right: 10, bottom: 10 }
    });
});

body.html

<div id="sampleForm" style="width: 500px; height: auto;"></div>

Learn more

More jQuery Form demos