Center input boxes in an HTML form

My form is currently set up to collect card details from users.

Right now, it looks like this:

card number:[..........] 

CVV code:[....]

Name as appears on card:[..........]

(Imagine the square brackets are input boxes and there are no dots inside.)

I want it to look like this:

card number: .......................... [........]

cvv: ...................................[........]

In simple terms, I want all the user input boxes to be centered for a neater appearance.

I am avoiding the use of CSS for this particular form due to business reasons.

This is my current code:

<br></br> Card Number: <input type="number"
            name="cardnumber" required="required" th:field="*{cardNumber}"
            maxlength="16" /> <br></br> Card Expiration: <select
            name='expireMM' id='expireMM' th:field="*{cardExpiry}"
            required="required">
            <option value=''>Month</option>
            <option value='01'>January</option>
            <option value='02'>February</option>
            <option value='03'>March</option>
            <option value='04'>April</option>
            <option value='05'>May</option>
            <option value='06'>June</option>
            <option value='07'>July</option>
            <option value='08'>August</option>
            <option value='09'>September</option>
            <option value='10'>October</option>
            <option value='11'>November</option>
            <option value='12'>December</option>
        </select> <select name='expireYY' id='expireYY' required="required">
            <option value=''>Year</option>
            <option value='10'>2015</option>
            <option value='11'>2016</option>
            <option value='12'>2017</option>
            <option value='13'>2018</option>
            <option value='14'>2019</option>
        </select> <input class="inputCard" type="hidden" name="expiry" id="expiry"
            maxlength="4" /> <br></br> Name (As Shown On Card): <input
            type="text" name="name" style="text-transform: uppercase"
            th:field="*{name}" required="required" /><br></br> CVV Code: <input
            type="number" name="cvvcode" maxlength="16" th:field="*{cardCVV}"
            required="required" /> <br></br>

Answer №1

In pure HTML, you have the option of constructing a table with fixed cells or experimenting with tab-stops:

<tab id=t1>

Alternatively, you can try:

<tab indent=20>

By adjusting the intent, you can specify the length of the tab.

If JavaScript or CSS is available to you, there are even more advanced and superior possibilities!

Answer №2

If you're looking for a solution to your requirements, consider the following structure. In case external CSS is not an option, inline styles could be used as an alternative. Here's a sample snippet:

<table>
<tr>
    <td>Card Number:</td>
    <td><input type="number" name="cardnumber" required="required" th:field="*{cardNumber}" maxlength="16" /></td>
</tr>
<tr>
    <td>Card Expiration:</td>
    <td>
        <select name='expireMM' id='expireMM' th:field="*{cardExpiry}" required="required">
        <option value=''>Month</option>
            <option value='01'>January</option>
            <option value='02'>February</option>
            <option value='03'>March</option>
            <option value='04'>April</option>
            <option value='05'>May</option>
            <option value='06'>June</option>
            <option value='07'>July</option>
            <option value='08'>August</option>
            <option value='09'>September</option>
            <option value='10'>October</option>
            <option value='11'>November</option>
            <option value='12'>December</option>
        </select>
        <select name='expireYY' id='expireYY' required="required">
            <option value=''>Year</option>
            <option value='10'>2015</option>
            <option value='11'>2016</option>
            <option value='12'>2017</option>
            <option value='13'>2018</option>
            <option value='14'>2019</option>
        </select>
        <input class="inputCard" type="hidden" name="expiry" id="expiry" maxlength="4" />
    </td>
</tr>
<tr>
    <td>Name (As Shown On Card):</td>           
    <td><input type="text" name="name" style="text-transform: uppercase" th:field="*{name}" required="required" /></td>
</tr>
<tr>
    <td>CVV Code:</td>          
    <td><input type="number" name="cvvcode" maxlength="16" th:field="*{cardCVV}" required="required" /></td>
</tr>   

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to Achieve an Overlapping Background Image Effect with Divs Using HTML and CSS

Is it possible to achieve the following scenario using just HTML and CSS? I want to display the background image of my HTML body through a clipped div. Keep in mind that the final website needs to be responsive (mobile-first), so any solution should accom ...

Unlock the Power of Sockets in JavaScript and HTML

How can I work with sockets in JavaScript and HTML? Could HTML5 features be helpful? Are there any recommended libraries, tutorials, or blog articles on this topic? ...

Visitors may not immediately notice the CSS/JavaScript modifications in their browsers

Currently, I am working on a web application utilizing Spring MVC and Hibernate, deploying it on Apache Tomcat 8. Most of my users access the app using Google Chrome. However, I have encountered an issue where whenever I update the CSS or JavaScript files ...

Is it possible to append the .active class to a div upon clicking a button?

I'm using bootstrap's tab system to create a "set up your account" page. The steps are displayed at the top of the page above the tab-panes. When a user clicks on an option in step one, it loads the step two tab and adds the active class to the c ...

How can I use AngularJS to save selected assets?

<div style="z-index: 1; position: absolute"ng-show="ctrl.company.selected"> <div style="" ng-repeat="Asset in ctrl.company.selected.Assets"> <div class="pd-5"style="width: 300px; background-color: white; border-bottom: gray solid ...

The hover effect fails to function properly after altering the background color. The default color setting is transparent

<button class="button-main slide">Slide Left</button> .button-main{ color: black; outline: none; background: transparent; border: none; letter-spacing: 0.0625em; padding: 8px 10px; text-transform: uppercase; font: b ...

Tips for incorporating unique images into each individual flex box

I am new to the world of coding, having just embarked on this journey less than a week ago. Following a tutorial by a developer on YouTube, I tried to add my own twist to the project in order to differentiate it from the original. However, I've hit a ...

Bootstrap 4 allows for the use of the d-lg-flex class to create a flexible column layout

I'm facing an issue with my table on smaller screens where some columns need to be hidden. Here's the code snippet I'm using: <table> <tr> <td>Normal 1</td> <td class="d-lg-flex d-none">hidden 1</t ...

The button is not properly aligned at the center of the flex container

My attempt to center a button in a fluid container with 100% vertical height and provide it with an offset from the bottom of the screen is almost successful, but the button is not perfectly centered - it is offset from the left. You can view the example i ...

In JavaScript or jQuery, what is the most optimal method to swap out all instances of a specific string within the body content without altering the rest of the body text?

Is there a way to replace specific occurrences of a string within a web page's body without disrupting other elements such as event listeners? If so, what is the best method to achieve this? For example: Consider the following code snippet: <body ...

Sending JSON Data from C# to External JavaScript File without Using a Web Server

Trying to transfer JSON data from a C# (winforms) application to a static HTML/JavaScript file for canvas drawing without the need for a web server. Keeping the HTML file unhosted is preferred. Without involving a server, passing data through 'get&ap ...

Why do certain full screen websites not align with my screen width properly?

When I use my 1920px wide screen and inspect the HTML tag with Chrome DevTools on websites like Firebase or Facebook Messenger, I notice a difference: https://i.sstatic.net/1nknq.png Despite my screen width being 1920px, these websites appear fullscreen ...

Utilizing a singular JavaScript method across various form interfaces

I seem to be facing a bit of a challenge with a task I've been working on. My goal is to have multiple forms (six in total) utilize a JavaScript method that I have created. These forms contain text input values which need to be checked, then passed t ...

Issue with thymeleaf causing malfunction in top-bar navigation on foundation framework

Looking for advice on creating a navigable menu using Foundation's "top-bar" component in an HTML template file with Spring MVC + thymeleaf. The menu bar appears but the sub-menus are not displaying when hovering over them. Sub-menus related to main ...

Delivering static HTML content on Google App Engine using Python

I'm struggling to load static .html pages for my Python application. Every time I try to access a link like index.html, the page remains blank and the server log shows a 404 error. This issue persists with other static .html files such as about.html. ...

Hovering over the Bootstrap dropdown menu will result in it being closed

I have implemented a dropdown menu with a secondary dropdown inside it. By incorporating JQuery code, I have enabled the functionality to open and close both dropdowns when hovering. As I hover over the primary dropdown labeled services and proceed to hov ...

Navigate through previous and next siblings in jQuery until a difference is found

Here's the issue: I have a div with multiple siblings positioned before and after it. For example: <div id="parent"> <div class="invalid"></div><!-- break iteration here !--> <div class="operand"></div> <div cl ...

The textarea field activates a select event listener whenever a button or link is clicked within the DOM

My DOM structure is pretty straightforward, consisting of a textarea, some buttons, and links. I've attached a select eventlistener to the textarea to monitor text selection by the user. const summary = document.getElementById("summary"); summary?. ...

Struggling with aligning items vertically in Bootstrap 4?

Despite my experience in programming, I am struggling with CSS and HTML. I am attempting to create a simple "Login Page" for my personal web application. GitHub: https://github.com/n-winspear/cashflow-webapp After trying various solutions suggested in ot ...

How can I incorporate a vertical line divider and a legend into a curved box using HTML and CSS?

https://i.sstatic.net/dj4zb.png I have this image that I need to divide into three sections with a legend at the top, similar to the image shown. So far, this is the code I have, but I'm struggling with creating the vertical line, adding space betwe ...